Hello all,
I am having a small problem with a little program I am writing for work. Basically it is suppose to take the information in one table and write it to another. Here is the code that I have for this..
Public Function Import()
Set cnn = CurrentProject.Connection
Set tbl = New ADODB.Recordset
tbl.Open "Imports", cnn, adOpenDynamic, adLockOptimistic
Set Meterhist = New ADODB.Recordset
Meterhist.Open "dbo_MTRHIST", cnn, adOpenDynamic, adLockOptimistic
intRow = tbl("Key")
'intEnd = (DMax("Key", "Imports"))
'Do Until intRow > intEnd
Do Until tbl.EOF
With tbl
tbl.Find "Key = '" & intRow & "'"
If .EOF Then
MsgBox "There is no information to Import.", vbInformation, ""
Else:
With Meterhist
Meterhist.AddNew
Meterhist("METERNUM") = "TEST"
Meterhist("EQNUM") = tbl("Vehicle")
Meterhist("EQDATE") = Date
Meterhist("EQTIME") = Time()
Meterhist("MTRVALUE") = tbl("ODOMETER")
Meterhist("EVENT") = "Import"
Meterhist.Update
intRow = (intRow + 1)
End With
End If
End With
Loop
'DoCmd.OpenQuery "Update_Meter_tbl", acViewNormal
End Function
Now here is the problem.. this code works perfectly fine when you add a watch to break on when the value of intRow changes if you continue after it breaks each time, it also works fine if you step through the the individual lines.. However if you try to run the code, with no watchs, and your not stepping through it, it will import the first line perfectly, then when it comes to the .Update of Meterhist for the second line it errors with "ODBC -- call failed". I have no idea why it is doing this... If anyone could help me I would be VERY greatful..
Thank you
-Osiris
I am having a small problem with a little program I am writing for work. Basically it is suppose to take the information in one table and write it to another. Here is the code that I have for this..
Public Function Import()
Set cnn = CurrentProject.Connection
Set tbl = New ADODB.Recordset
tbl.Open "Imports", cnn, adOpenDynamic, adLockOptimistic
Set Meterhist = New ADODB.Recordset
Meterhist.Open "dbo_MTRHIST", cnn, adOpenDynamic, adLockOptimistic
intRow = tbl("Key")
'intEnd = (DMax("Key", "Imports"))
'Do Until intRow > intEnd
Do Until tbl.EOF
With tbl
tbl.Find "Key = '" & intRow & "'"
If .EOF Then
MsgBox "There is no information to Import.", vbInformation, ""
Else:
With Meterhist
Meterhist.AddNew
Meterhist("METERNUM") = "TEST"
Meterhist("EQNUM") = tbl("Vehicle")
Meterhist("EQDATE") = Date
Meterhist("EQTIME") = Time()
Meterhist("MTRVALUE") = tbl("ODOMETER")
Meterhist("EVENT") = "Import"
Meterhist.Update
intRow = (intRow + 1)
End With
End If
End With
Loop
'DoCmd.OpenQuery "Update_Meter_tbl", acViewNormal
End Function
Now here is the problem.. this code works perfectly fine when you add a watch to break on when the value of intRow changes if you continue after it breaks each time, it also works fine if you step through the the individual lines.. However if you try to run the code, with no watchs, and your not stepping through it, it will import the first line perfectly, then when it comes to the .Update of Meterhist for the second line it errors with "ODBC -- call failed". I have no idea why it is doing this... If anyone could help me I would be VERY greatful..
Thank you
-Osiris
Last edited: