Solved

VBA SQL update query

Posted on 2014-04-04
5
3,970 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now