Solved

VBA SQL update query

Posted on 2014-04-04
5
4,017 Views
Last Modified: 2014-04-04
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
0
Comment
Question by:UserName935
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39978995
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
0
 

Author Comment

by:UserName935
ID: 39979012
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
0
 
LVL 38

Accepted Solution

by:
Jim P. earned 500 total points
ID: 39979081
Try this oh:

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' "

Open in new window

0
 

Author Closing Comment

by:UserName935
ID: 39979091
PAY-DIRT !!!! What the Heck !!

AAHHH, It was these things (  ).

Awesome, thank you !!!!!!
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 39979106
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.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question