Results 1 to 8 of 8
  1. #1
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99

    Update query with SQL

    Hi Guys, I have a update query in command click event, and the SQL was like below, but system give me a warning that missing the end of the code(Sorry for my poor english),could somebody help find what's the problem?
    Thanks in advance.



    UPDATE tblInventoryInfo SET tblInventoryInfo.StockLevel= tblInventoryInfo.StockLevel-Me.Qty.Value _
    Where(((tblInventoryInfo.PartNumber)="Me.PartNumbe r") AND ((tblInventoryInfo.LotNumber)="Me.LotNumber")));
    Last edited by blueraincoat; 03-17-2011 at 11:30 PM.

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You have to construct the query in a string variable and populate it with the values from the form controls you reference.

    The following code assumes that the part number and lot number fields in the table are numeric datatypes

    Code:
    Dim mySQL As String
    mySQL = "UPDATE tblInventoryInfo SET tblInventoryInfo.StockLevel= tblInventoryInfo.StockLevel-" & Me.Qty
    mySQL = mySQL & " Where tblInventoryInfo.PartNumber=" & Me.PartNumber & " AND tblInventoryInfo.LotNumber=" & Me.LotNumber
     
    CurrentDb.Execute mySQL, dbFailOnError
    If the part and lot number fields are text fields, the code would look like this:

    Code:
    Dim mySQL As String
    mySQL = "UPDATE tblInventoryInfo SET tblInventoryInfo.StockLevel= tblInventoryInfo.StockLevel-" & Me.Qty
    mySQL = mySQL & " Where tblInventoryInfo.PartNumber='" & Me.PartNumber & "' AND tblInventoryInfo.LotNumber='" & Me.LotNumber & "'"
     
    CurrentDb.Execute mySQL, dbFailOnError

  3. #3
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    Thank you jzwp11.
    But when I ran the code you give in my db, it gave an error 3061 too few parameters, what should I do ...

  4. #4
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    I search the Internet and reviewed my db.
    I have two tabels on is tblInventoryInfo, the other is tblPartsOutbound.
    The main form is based on tblPartsOutbound, my purpose is when I take parts out of inventory, I'll keep the record in tblPartOutbound and update the stocklevel of the parts in inventory.
    Could this be done?

  5. #5
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    I'm awfully sorry,jzwp11
    Your code works perfec without any question. I changed the name of one of my fields.
    Thank you very much.
    I'm going to mark this thread as solved.

  6. #6
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Actually the better way to handle inventory is with 1 table where you record additions to as well as subtractions from inventory. You might take a look at this site from Allen Browne where he discusses inventory control

  7. #7
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    Thank you for the suggestion.

  8. #8
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome; good luck with your project.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 01-31-2011, 08:31 AM
  2. How can I update a query using VBA?
    By thestappa in forum Programming
    Replies: 2
    Last Post: 06-28-2010, 04:01 PM
  3. update query
    By dollygg in forum Queries
    Replies: 1
    Last Post: 04-24-2010, 12:32 AM
  4. Update Query with parameter query
    By mimikate in forum Queries
    Replies: 2
    Last Post: 03-16-2010, 09:10 PM
  5. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums