N
Nick 'The Database Guy'
..... I beleive that my case is a little different.
I am getting an ODBC call fail error message when I try to run the
following code:
' This subprocedure does the manual work of adding the amount (this
can be positive or & _
negative) to the current holding
Public Function ExecuteTrade(Account As Long, NumberOfUnits As Long)
As Variant
On Error GoTo err_ExecuteTrade
Dim sql As String
Dim db As dao.Database
Dim rs As dao.Recordset
Dim lngBalance As Long
DBGcounter = DBGcounter + 1
sql = "SELECT AccountID, Holding " & _
"FROM tblAccount " & _
"WHERE AccountID = " & Account
Set db = CurrentDb()
Set rs = db.OpenRecordset(sql, dbOpenDynaset, dbSeeChanges)
With rs
.Edit
!Holding = !Holding + NumberOfUnits
.Update
ExecuteTrade = !Holding
.Close
End With
exit_ExecuteTrade:
Set rs = Nothing
db.Close
Set db = Nothing
Exit Function
err_ExecuteTrade:
If Err.Number = 3146 Then
RelinkTables
Resume
Else
ExecuteTrade = False
Resume exit_ExecuteTrade
End If
End Function
This code fails on the line "Set rs = db.OpenRecordset(sql,
dbOpenDynaset, dbSeeChanges)", when I am trying to open the record
before editing it. The mystifing thing is that it works on 53 records
before this error occurs. I have checked and the record is there,
however I can't even manually SELECT it while the code is running in
break mode, however when I stop the code it is there. Can anyone help
me? Thanks in advance if you can. Cheers
I am getting an ODBC call fail error message when I try to run the
following code:
' This subprocedure does the manual work of adding the amount (this
can be positive or & _
negative) to the current holding
Public Function ExecuteTrade(Account As Long, NumberOfUnits As Long)
As Variant
On Error GoTo err_ExecuteTrade
Dim sql As String
Dim db As dao.Database
Dim rs As dao.Recordset
Dim lngBalance As Long
DBGcounter = DBGcounter + 1
sql = "SELECT AccountID, Holding " & _
"FROM tblAccount " & _
"WHERE AccountID = " & Account
Set db = CurrentDb()
Set rs = db.OpenRecordset(sql, dbOpenDynaset, dbSeeChanges)
With rs
.Edit
!Holding = !Holding + NumberOfUnits
.Update
ExecuteTrade = !Holding
.Close
End With
exit_ExecuteTrade:
Set rs = Nothing
db.Close
Set db = Nothing
Exit Function
err_ExecuteTrade:
If Err.Number = 3146 Then
RelinkTables
Resume
Else
ExecuteTrade = False
Resume exit_ExecuteTrade
End If
End Function
This code fails on the line "Set rs = db.OpenRecordset(sql,
dbOpenDynaset, dbSeeChanges)", when I am trying to open the record
before editing it. The mystifing thing is that it works on 53 records
before this error occurs. I have checked and the record is there,
however I can't even manually SELECT it while the code is running in
break mode, however when I stop the code it is there. Can anyone help
me? Thanks in advance if you can. Cheers