|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#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? |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
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 |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Vba neebie needed code cleaned up |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|