Solved

update SQL Query in VBA Using Variables

Posted on 2007-11-27
3
799 Views
Last Modified: 2012-05-05
I am trying to use an update query but cannot get the syntax correct.  Please advise.  This is obviously my hardest thing to grasp (SQL Query syntax with variables).

For Each varItm In Me.lstVendorPartsList.ItemsSelected
        varPartID = Me.lstVendorPartsList.ItemData(varItm)

            DoCmd.SetWarnings False
            Dim sqlStr As String
            sqlStr = "UPDATE " & varTmpTableName1 & " SET " & varTmpTableName1 & ".[qtytopurchase] = " & varUpdateQty _
                        & " WHERE (((" & varTmpTableName1 & ".PartID)= " & varPartID

                       
                 'MsgBox sqlStr
                DoCmd.RunSQL sqlStr
            DoCmd.SetWarnings True
    Next
0
Comment
Question by:Lasers07
[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 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 350 total points
ID: 20360212
try

sqlStr = "UPDATE [" & varTmpTableName1 & "] SET [qtytopurchase] = " & varUpdateQty _
                        & " WHERE PartID= " & varPartID
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 20360218
What are data types of varUpdateQTY, carPartID?
You need not be so explicit in naming the table every time you mention a field in the table.
sqlStr = "UPDATE " & varTmpTableName1 & " SET  [qtytopurchase] = " & varUpdateQty _
                        & " WHERE  PartID)= " & varPartID
0
 

Author Closing Comment

by:Lasers07
ID: 31427377
Thanks Cap!  I think u are on a roll getting points off my syntax questions!  LOL.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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