SQL Update (1 Viewer)

IanT

Registered User.
Local time
Today, 18:40
Joined
Nov 30, 2001
Messages
191
Hi

I am using the SQL statement below with a variable which changes via a loop, can anyone advise where the SQL is incorrect as I get an error.

DoCmd.RunSQL "UPDATE" & myvar & "SET" & myvar & ".LOB = 'MOTOR'" & _
"WHERE (((" & myvar & ".LOB) Like '*mot*'));"
 

DCrake

Remembered
Local time
Today, 18:40
Joined
Jun 8, 2005
Messages
8,626
First of all do a Debug.print to view the actual sql statement

Debug.Print "UPDATE" & myvar & "SET" & myvar & ".LOB = 'MOTOR'" & _
"WHERE (((" & myvar & ".LOB) Like '*mot*'));"

Then see what it looks like.

Also you have not said what error you are getting.
 

Kenln

Registered User.
Local time
Today, 13:40
Joined
Oct 11, 2006
Messages
551
I know this sounds foolish, but a common problem I have when creating SQL like your example is remembering to include spaces.

For example
If myvar = "tbl_My_Table" then your script
Code:
"UPDATE" & myvar
might give this result

Updatetbl_My_Table

Instead of
Update tbl_My_Table

So... you could try
Code:
"UPDATE " & myvar
Just a problem that I know I have to watch for.
 

Users who are viewing this thread

Top Bottom