Solved

VBA SQL update query

Posted on 2014-04-04
5
4,236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

615 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