docmd.runsql update issue

abbers_01

Registered User.
Local time
Today, 13:42
Joined
Aug 31, 2007
Messages
45
the table I'm referencing when using runsql code in vb, can it not have spaces? Cause I can't figure out what is wrong with my code other than perhaps it isn't able to find the table I am referencing.

My Code:
Dim SQL As String
SQL = "UPDATE Work Order Content SET [WO Status] =" & "'" & Me.WOStatusInput & "'" & " WHERE [Work Order Number] =" & Me.OrderID
DoCmd.RunSQL SQL

The Output
UPDATE Work Order Content SET [WO Status] = 'Waiting on Parts' WHERE [Work Order Number] = 29333

The error I get is a:
Run-Time error '3144':
Syntax error UPDATE statement

If anyone can clarify this for me, or point out my mistake it would be greatly appreaciated. Thanks.
 
You would have to bracket it, just as you did the field. You really should get rid of the spaces though.
 
thanks pbaldy that worked for me.

ya, when i started this project it was my first time doing this, and now I have it loaded with relationships and code refering to that table, I really don't want to go back through everything, guess thats my laziness. But now I know for the future. Thanks again.

My code is now:

Dim SQL As String
SQL = "UPDATE [Work Order Content] SET [WO Status] =" & "'" & Me.WOStatusInput & "'" & " WHERE [Work Order Number] =" & "'" & Me.OrderID & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL SQL
DoCmd.SetWarnings True
 
thanks pbaldy that worked for me.

ya, when i started this project it was my first time doing this, and now I have it loaded with relationships and code refering to that table, I really don't want to go back through everything, guess thats my laziness. But now I know for the future. Thanks again.

My code is now:

Dim SQL As String
SQL = "UPDATE [Work Order Content] SET [WO Status] =" & "'" & Me.WOStatusInput & "'" & " WHERE [Work Order Number] =" & "'" & Me.OrderID & "'"
DoCmd.SetWarnings False
DoCmd.RunSQL SQL
DoCmd.SetWarnings True

Just a quick FYI for you. Since you are using the SetWarnings command, you should, if you don't already, include an error handler and in the very first line of your error handler put

DoCmd.SetWarnings True

because if you don't and it errors out while running the SQL statement, you will find yourself without warnings because it didn't get to the place where it reset the warnings.
 

Users who are viewing this thread

Back
Top Bottom