Link to home
Start Free TrialLog in
Avatar of UserName935
UserName935

asked on

VBA SQL update query

sometimes I f'ing hate access, SSMS take me away......

Access 2010, win7

Issue: SQL VBA Update query not functioning.  
Error: Syntax error on update statement
Yes, I dimmed  strUpdateSQL string
Statement:

strUpdateSQL = "UPDATE MOR_ChartDBSource_Template" _
 & "SET (MOR_ChartDBSource_Template.Jan = '" & ResultString & "')" _
 & "WHERE ((MOR_ChartDBSource_Template.YEAR) Like '2014') AND ((MOR_ChartDBSource_Template.CHARTDB_BIN) Like 'calcHC')" _
 & "AND (MOR_ChartDBSource_Template.ORG_ABBR Like 'Total') AND (MOR_ChartDBSource_Template.MOR_GROUP Like 'CE Prog Other')"

DoCmd.RunSQL strUpdateSQL
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

Try putting spaces at the end of each line. Also it may just be the way that the EE textbox formatted it, but there were missing double quotes and ampersand signs (&).

strUpdateSQL = "UPDATE MOR_ChartDBSource_Template " _
& "SET (MOR_ChartDBSource_Template.Jan = '" & ResultString & "') " _
& "WHERE ((MOR_ChartDBSource_Template.YEAR) Like '2014') AND " _  & "((MOR_ChartDBSource_Template.CHARTDB_BIN) Like 'calcHC') " _
& "AND (MOR_ChartDBSource_Template.ORG_ABBR Like 'Total') AND " _  & "(MOR_ChartDBSource_Template.MOR_GROUP Like 'CE Prog Other')"

DoCmd.RunSQL strUpdateSQL
Avatar of UserName935
UserName935

ASKER

Umm NICE TRY !!

It blew up, when pasting into the vba it all turn red, so I made some changes and it continues to fail to function.

This is what I changed it to.

strUpdateSQL = "UPDATE MOR_ChartDBSource_Template " & _
 "SET (MOR_ChartDBSource_Template.Jan = '" & ResultString & "')" & _
 "WHERE ((MOR_ChartDBSource_Template.YEAR) Like '2014') AND " & _
 "((MOR_ChartDBSource_Template.CHARTDB_BIN) Like 'calcHC') " & _
 "AND (MOR_ChartDBSource_Template.ORG_ABBR Like 'Total') AND " & _
 "(MOR_ChartDBSource_Template.MOR_GROUP Like 'CE Prog Other')"

DoCmd.RunSQL strUpdateSQL
ASKER CERTIFIED SOLUTION
Avatar of Jim P.
Jim P.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PAY-DIRT !!!! What the Heck !!

AAHHH, It was these things (  ).

Awesome, thank you !!!!!!
Glad I could help.


For future reference the Access query builder puts in a bunch of wasteful parentheses.
About the only time you need the parentheses is if you are using the IN keyword or combining AND and OR statements.