schmir1
asked on
Can't get ADO Recordset to work
I'm trying to get the following to work. I'm not to good with ADO yet.
Dim rstTimeEst As New ADODB.Record
Dim strQuery As String
Dim dbBat1 As New Command
strQuery = "DELETE * FROM Commitment_Time_Est_Data"
CurrentDb.Execute strQuery
dbBat1.ActiveConnection = CurrentProject.Connection
dbBat1.CommandText = "SELECT * FROM Commitment_Time_Est_Data"
rstTimeEst.Open dbBat1, , adOpenForwardOnly, adLockOptimistic
rstTimeEst!Commitment_ID = !Commitment_ID
rstTimeEst.Update
ASKER
I got the following errors. See the errors list in the comments:
Dim rstTimeEst As ADODB.Recordset
'CurrentProject.Execute "DELETE * FROM Commitment_Time_Est_Data" 'Run-time error '438':
'Object doesn 't support this property or method
Set rstTimeEst = New ADODB.Recordset
rstTimeEst.Open "SELECT * FROM Commitment_Time_Est_Data", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rstTimeEst!Commitment_ID = 1 'Run-time error '3021': Either BOF or EOF is True, or the current record has been deleted.
'Requested operation requires a current record.
rstTimeEst.Update
rstTimeEst.Close
Set rstTimeEst = Nothing
Dim rstTimeEst As ADODB.Recordset
'CurrentProject.Execute "DELETE * FROM Commitment_Time_Est_Data" 'Run-time error '438':
'Object doesn 't support this property or method
Set rstTimeEst = New ADODB.Recordset
rstTimeEst.Open "SELECT * FROM Commitment_Time_Est_Data",
rstTimeEst!Commitment_ID = 1 'Run-time error '3021': Either BOF or EOF is True, or the current record has been deleted.
'Requested operation requires a current record.
rstTimeEst.Update
rstTimeEst.Close
Set rstTimeEst = Nothing
ASKER
I had to give up on ADO code and go back to something I know, DAO.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That makes sense. The data is generated every time the user presses the button so I delete the old stuff. Thanks for your help.
Dim rstTimeEst As ADODB.Recordset
CurrentProject.Execute "DELETE * FROM Commitment_Time_Est_Data"
Set rstTimeEst = New ADODB.Recordset
rstTimeEst.Open "SELECT * FROM Commitment_Time_Est_Data",
rstTimeEst!Commitment_ID = <some value here>
rstTimeEst.Update
rstTimeEst.Close
Set rstTimeEst = Nothing