Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

update SQL Query in VBA Using Variables

Posted on 2007-11-27
3
Medium Priority
?
807 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 1400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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