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

Open in new window

schmir1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You need to open a Recordset:

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",  CurrentProject.Connection, adOpenKeyset, adLockOptimistic

rstTimeEst!Commitment_ID = <some value here>
rstTimeEst.Update

rstTimeEst.Close
Set rstTimeEst = Nothing
0
schmir1Author Commented:
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
0
schmir1Author Commented:
I had to give up on ADO code and go back to something I know, DAO.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
This one:

CurrentProject.Execute "DELETE * FROM Commitment_Time_Est_Data"  

Should be:

CurrentProject.CONNECTION.Execute "blah blah"

sorry about that ...

as to the other ... you should always check to see if your REcordset has returned a value before attempting to update it:

If Not(rstTimeEst.EOF and rstTimeEST.BOF) Then
  '/do your update here
End If

However, since you are (apparently) deleting every record in the Commitment_Time_Est_Data table, you cannot use a Update query for this, you'd need to run an INSERT query. You can achieve the same thing like this:

CurrentProject.Connection.Execute "DELETE * FROM Commitment_Time_Est_Data"  
CurrentProject.Connection.Execute "INSERT INTO Commitment_Time_Est_Data(Commitment_ID) VALUES(1)"

Assuming the datatype of Commitment_ID is Numeric, this is all you'd need to do.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
schmir1Author Commented:
That makes sense.  The data is generated every time the user presses the button so I delete the old stuff.  Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.