problem with my SQL??

mlopes1

Registered User.
Local time
Today, 10:13
Joined
Sep 4, 2002
Messages
76
The following code runs without errors but also does not update the table correctly. If I take the values of the 3 variables below and plug them into the SQl, it works correctly and makes the updates. How do you reference variable? I went through Access Help but could not find my mistake below.

bName = "American"
criteria1 = "*Test*"
criteria2 = "Longhorn"

strSQL = "UPDATE [New_Items] SET [New_Items].segment = "" & criteria2 & "" " & _
"WHERE (((New_Items.[Desc]) Like "" & criteria1 & "") AND ((New_Items.Brand) = "" & bName & "")) "
DoCmd.RunSQL strSQL

If you need me to post the code that does work let me know. Its basically the same as above except the ' & variable &' are replaced with the actual values.

Thanks as always,

Marco
 
Try this instead:


strSQL = "UPDATE [New_Items] SET [New_Items].segment = """ & criteria2 & """ " & _
"WHERE (((New_Items.[Desc]) Like """ & criteria1 & """) AND ((New_Items.Brand) = """ & bName & """)) "

The difference is with the ". You did not have enough. In VBA, you need "" to print ". Following me?

Hope it helps
 
Thanks Mario... that was exactly it.

Also a note for anyone who might reference this.
When I first tried your solution I put "" " and just adding that space between the "s makes it not work. They must be 3 consecutive parentheses: """ & test & """

Thanks again!
 

Users who are viewing this thread

Back
Top Bottom