Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 26th, 2006, 08:37 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
Vba neebie needed code cleaned up

hola, well i am slowing grinding thru this.
i am currently getting an error when i run "ProdLineUp" stating tha the table "tnn1" already exist BUT visiably there is not a table tnn1 when i go to the table section in my database.

any ideas:

Code:
code below:

Private Sub CreateTable()
Const strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Feature Animation\Finance\RMT's\udpate tble Downtime RMT2.mdb;Persist Security Info=False"

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command

cnn.ConnectionString = strConnection
cnn.Open

cmd.ActiveConnection = cnn
cmd.CommandText = "create table tnn1 (a number, b varchar(10))"

cmd.Execute
cnn.Close

End Sub

Private Sub DeleteTable()
DoCmd.SetWarnings False
DoCmd.DeleteObject acTable, "tnn1"
DoCmd.SetWarnings True
End Sub

Public Function ProdLineUp()
    Dim rsEmployee As Recordset, rsUpdate As Recordset
    Dim qdf As QueryDef
    Dim X As Integer
    Dim strSQL As String
    
    Set rsEmployee = CurrentDb.OpenRecordset("qry_Downtime_Limited_Count_Employee")
    rsEmployee.MoveLast
    rsEmployee.MoveFirst
    
    Set qdf = CurrentDb.QueryDefs("qry_Update")
    
    For X = 1 To rsEmployee.RecordCount
        qdf.Parameters(0) = rsEmployee.Fields("Last_Name")
        Set rsUpdate = qdf.OpenRecordset
        
        
        Call CreateTable
        DoCmd.RunSQL "INSERT INTO tnn1 SELECT Last_Name as a"
        DoCmd.Requery "qry_tnn_append"
        
        Call DeleteTable
        rsUpdate.Close
        rsEmployee.MoveNext
    Next X

    Set rsExport = Nothing
    Set rsTechs = Nothing
    Set qdf = Nothing
    
    MsgBox "Limited Employee is now up to date"
    
End Function

Reply With Quote
  #2  
Old May 26th, 2006, 09:54 PM
ProEdge's Avatar
ProEdge ProEdge is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2004
Location: Somewhere I belong
Posts: 1,565 ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level)ProEdge User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 17 h 7 m 15 sec
Reputation Power: 39
I don't have an answer as to why the table is visibly not there but I do know that if you plan to re-create a table, you need to drop/delete it first. You need to make sure that you drop the table first in your CreateTable subroutine, otherwise you run into this error. Try it out and let us know what happens.
__________________
Keep it Prodigy, Keep it Real

Reply With Quote
  #3  
Old May 27th, 2006, 12:15 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 57 m 26 sec
Reputation Power: 181
Make sure the db you're using in your code is the same db you're checking manually.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #4  
Old May 27th, 2006, 02:35 AM
pmlakshmis pmlakshmis is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 21 pmlakshmis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 7 m 47 sec
Reputation Power: 0
try to add the following code,

on error resume next ' use this line before creating table

' use the code below after executing create command

if err.number = -2147217900 then
msgbox " Table already Exists !"
end if

' and u can just proceed inserting ur data and etc... Carry on with other things. the error will be handled with the above code. after inserting , display the data and c whether table exists or not.

thanks

Reply With Quote
  #5  
Old May 30th, 2006, 12:49 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
i am getting the "Table already Exists !" error, namely, error = -2147217900.

is that a data type mismatch in my Insert Into statement?

by the way, how do i step through my code. Currently, I am placing the cursor on the Function Name and selecting the "Run Sub/User Form" but how do i go through it line by line via one of the F# keys?

Reply With Quote
  #6  
Old May 30th, 2006, 02:48 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
alright......i figure out why my table wasn't updating. i made a copy of the database and didn't update the coding for createtable() with the new name.

here is my situation now:

i am being prompted to enter in the parameters for "Last_Name". should this fitler through on it own since my "qry_Downtime_Limited_Count_Employee" gathers all of the "Last_Name"s and i loop through it my X=1 and Next X?

Also, when I manually enter the parameters, ("Last_Name") i am not interting into the newly created table.

thansk
tuktuk

Reply With Quote
  #7  
Old May 30th, 2006, 08:04 PM
tuktuk tuktuk is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 104 tuktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 11 m 18 sec
Reputation Power: 5
ahhhh, it is AMAZING how the F8 button assits with figuring out errors.

Okay, i need to add to my insert statement a where clause for the X to Next X values.
I am filtering through the set of names correctly but i am not gathering infor for NameOne; x, Name two; x+1; name three; x+2.

DoCmd.RunSQL "INSERT INTO tnn1 (a,b) SELECT tbl_Downtime_Production_Count.Last_Name, tbl_Downtime_Production_Count.Production_Name FROM tbl_Downtime_Production_Count WHERE tbl_Downtime_Production_Count.Last_Name = rsEmployee.Fields("Last_Name");"

i am not sure if this is correct syntax but my theory is dead on..i think. note: the rsEmployee is set in the code above

EDITED POST--------------------see below

it thought i'd add the entire code, current this is fucntioning correct when i step through but i am prompted to manually type in the parameters for the 'insert into' statement to take. SHOULD THE WHERE statement be included in my INSERT INTO statemetn?

also, if i drag my cursor over rsUpdate it states "= nothing"..

i am close.....thansk for the help


Code:
ProdLineUp()

    Dim rsEmployee As Recordset
    Dim rsUpdate As Recordset
    Dim qdf As QueryDef
    Dim X As Integer
    Dim strSQL As String
    
    Set rsEmployee = CurrentDb.OpenRecordset("qry_Downtime_Limited_Count_Employee")
    rsEmployee.MoveLast
    rsEmployee.MoveFirst
    
    Set qdf = CurrentDb.QueryDefs("qry_Update")
    
    For X = 1 To rsEmployee.RecordCount
        qdf.Parameters(0) = rsEmployee.Fields("Last_Name")
        Set rsUpdate = qdf.OpenRecordset
        
        Call DeleteTable
        On Error Resume Next ' use this line before creating table
            If Err.Number = -2147217900 Then
            MsgBox " Table already Exists !"
            End If
        Call CreateTable
            
        
        DoCmd.RunSQL "INSERT INTO tnn1 (a,b) SELECT tbl_Downtime_Production_Count.Last_Name, tbl_Downtime_Production_Count.Production_Name FROM tbl_Downtime_Production_Count WHERE tbl_Downtime_Production_Count.Last_Name=paramLast_  Name;"
        DoCmd.RunSQL "INSERT INTO tbl_tnn1_Complied ( Last_Name, ProdNumber ) SELECT tnn1.a, tnn1.b FROM tnn1;"
        
        rsUpdate.Close
        rsEmployee.MoveNext
        
    Next X

    Set rsUpdate = Nothing
    Set rsEmployee = Nothing
    Set qdf = Nothing
    
    MsgBox "Limited Employee is now up to date"
    
End Function


thanks
terry

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Vba neebie needed code cleaned up


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT