VBA SQL Update

Jamz

Registered User.
Local time
Today, 07:09
Joined
Jan 16, 2012
Messages
31
Hi Guys,

Trying to update a table [WR] with todays date where the text box on the form = ID

Code:
    closesql = "UPDATE [WR] SET DateClose '" & Date & "' = WHERE ID = '" & Me.ID & "';"
    DoCmd.RunSQL closesql

Pops up an error message saying there is SYNTAX error in update statement, but i must be being blind
 
Code:
closesql = "UPDATE [WR] SET DateClose '" & Date & "' = WHERE ID = '" & Me.ID & "';"
    DoCmd.RunSQL closesql

Your "=" before WHERE is in the wrong place and whereas strings are enclosed in quotes (" or '), Dates are enclosed between hash symbols (#).

I think this will do you.

Code:
closesql = "UPDATE [WR] SET DateClose = #" & Date & "# WHERE ID = '" & Me.ID & "'"
    DoCmd.RunSQL closesql

This assumes that Me.ID is a string. If it's a number you'll need.

Code:
closesql = "UPDATE [WR] SET DateClose = #" & Date & "# WHERE ID = " & Me.ID
    DoCmd.RunSQL closesql
 
Or even:
Code:
    closesql = "UPDATE [WR] SET DateClose =[COLOR=Blue] Date() [/COLOR]WHERE ID = '" & Me.ID & "';"
    DoCmd.RunSQL closesql


    closesql = "UPDATE [WR] SET DateClose =[COLOR=Blue] Date()[/COLOR] WHERE ID = " & Me.ID & ";"
    DoCmd.RunSQL closesql
 

Users who are viewing this thread

Back
Top Bottom