Question Update query has error 424 Object required

fudgematico

Registered User.
Local time
Today, 10:09
Joined
Jul 10, 2013
Messages
13
I am trying to create an update query for the first time and am a little stumped of how it works. I am trying to update a field in a table with the current date as a request.

I have a table named tblTest and a field named Date2 that I am trying to update with the current date, the button that the VBA is applied to is in a form name frmTest. This is my code:

Private Sub Command39_Click()
Dim t1 As Date
t1 = Date
db.Execute("update tblTest set tblTest.Date2") = t1
End Sub

But when I press the button I get:
Run time error '424'
Object Required

It highlights the 4th of code, please help

Thank in advance
 
Try

db.Execute "update tblTest set tblTest.Date2 = #" & t1 & "#"
 
Thanks for the quick reply :)

I have put that in but still the same error?
 
If that's all the code, you never set the db variable. Try

CurrentDb.Execute "update tblTest set tblTest.Date2 = #" & t1 & "#"
 
Ahh great stuff that works :)

But it updates all of the records at once? Is there a way to update one record using a value in a textbox? maybe if the ID was in a textbox the code would read it and update just that record?
 
Figured that would be the next question. :p

Sure; presuming the ID is numeric:

CurrentDb.Execute "update tblTest set tblTest.Date2 = #" & t1 & "# WHERE FieldName = " & Forms!FormName.TextboxName
 
No problem, and welcome to the site by the way!
 

Users who are viewing this thread

Back
Top Bottom