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
Solved

update SQL Query in VBA Using Variables

Posted on 2007-11-27
3
787 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
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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 …

840 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