Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access VBA SQL Syntax Error for Line continuation

Posted on 2015-02-20
6
Medium Priority
?
140 Views
Last Modified: 2016-02-10
I made the following DSum Update query in the editor and pasted into VBA using the   " &  _   for line continuation. Code turns red.  Tried two different blocks as below. Only the third line in the first block below turns red. Can I use DSUM in VBA like this?

strSQL7 = strSQL7 & " UPDATE tblRateCharges INNER JOIN tblRate ON"
strSQL7 = strSQL7 & " tblRateCharges.RateID = tblRate.RateID SET"
strSQL7 = strSQL7 & " tblRate.AddlFuelChargeable = DSum("Charge","tblRateCharges","FuelChargeable= -1")"    

strSQL7 = "UPDATE tblRateCharges INNER JOIN tblRate ON " & _
        "tblRateCharges.RateID = tblRate.RateID SET " & _
        "tblRate.AddlFuelChargeable = DSum("Charge","tblRateCharges","FuelChargeable= True")"
0
Comment
Question by:ExpressMan1
[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
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Eric Sherman earned 2000 total points
ID: 40621647
Try this ...

strSQL7 = strSQL7 & " tblRate.AddlFuelChargeable = " & DSum("Charge","tblRateCharges","FuelChargeable= -1")  

ET
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40621713
strSQL7 = strSQL7 & " tblRate.AddlFuelChargeable = DSum(""Charge"",""tblRateCharges"",""FuelChargeable= -1"")"     

Open in new window

You have to double each double quote being inside the string.
0
 

Author Closing Comment

by:ExpressMan1
ID: 40621723
Perfect! No longer red.  Thank You.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 71

Expert Comment

by:Qlemo
ID: 40621731
But still wrong, probably. Do you want to insert the evaluated DSum into the UPDATE, or let the UPDATE do the calculation?
0
 

Author Comment

by:ExpressMan1
ID: 40621799
Let the UPDATE do the calculation.  The field tblRate.AddlFuelChargeable is updating as planned.

Thanks to both of you.
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 40621837
http:#a40621647 calculates the value, then adds it as a literal. But if it works for you ...
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

730 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