Solved

VBA SQL update query

Posted on 2014-04-04
5
4,129 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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

752 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