Update Query Syntax Error

StuckfromPR

Registered User.
Local time
Today, 12:09
Joined
Sep 15, 2008
Messages
18
I am trying to run the following query and it's giving me this error:

Microsoft Visual Basic

Run-time error '3144':
Syntax error in UPDATE statement.

[
Code:
stSql = "UPDATE Table1 " & _
" SET Table1.Field1 = '" & Me.txt1 & "', Table1.Field2 = '" & Me.txt2 & " '" & _
" WHERE Table1.Field3 = '" & Me.txt3 & "' AND Table1.Field4 = '" & Me.txt4 & "' AND Table1.Field5 = '" & Me.txt5 & "' AND Table1.Field6 = '" & Me.txt6 & "';"
    
DoCmd.RunSQL stSql, dbFailOnError
 
MsgBox "Table Updated"


I don't know what I am doing wrong! Please Help!!!
 
Here's how to debug these kinds of things. Add

Debug.Print stSql

after the string is built but before it's run. That will print the final SQL out to the Immediate window, where you can examine it. If you don't spot the problem right away, you can copy/paste that SQL into a new query and try to run it, which might give you a more descriptive error. If you're still stuck, post the SQL here.
 
I did that, this is the String:

UPDATE Table1 SET Table1.Field1 = 'Test', Table1.Field2 = 'Medium ' WHERE Table1.Field3 =
'Exxxxxx' AND Table1.Field4 = '54' AND Table1.Field5 = '10 - October' AND Table1.Field6 = '1';
 
Did you paste it into a blank query and try to run it? What are the data types of field4 and field6? If numeric, the values should not be surrounded by single quotes.
 

Users who are viewing this thread

Back
Top Bottom