Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56

    Ado update for multiply records

    Hi, im practising with ADO and i have the following problem
    I need to subtrack from order details quantity with productid.
    but how can i use subtrack? it gives me debug error

    here is the code

    Private Sub button_Click()
    Dim lookupcheck As String
    Dim apo As Integer
    Dim cnn1 As ADODB.Connection
    Dim myrecordset As New ADODB.Recordset
    Set cnn1 = CurrentProject.Connection
    myrecordset.ActiveConnection = cnn1

    myrecordset.Open " SELECT * " & _
    " FROM [products] INNER JOIN TransactionLine ON " & _
    "[products].PrId = TransactionLine.Prid ", cnn1, adOpenStatic, adLockOptimistic



    lookupcheck = DLookup("[CurrentStock]", "products", "products.prid=TransactionLine.PrId")
    If DLookup("[Apothema]", "products", "products.prid=TransactionLine.PrId") < Forms![transactionline].Quantity Then
    MsgBox "Error : " & lookupcheck & "", vbCritical, "Error"


    Else
    Do Until myrecordset.EOF

    myrecordset.Fields("CurrentStock") = Forms![transactionline].Quantity - myrecordset.Fields("CurrentStock")
    myrecordset.UpdateBatch '//(all the records like productid=1,2,3,or 4 with different quantity)
    myrecordset.MoveNext
    Loop

    MsgBox "Updates Success", , "Update"
    End If

    myrecordset.Close
    Set myrecordset = Nothing

    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    For one thing, the SQL and DLookup syntax is wrong. Variables must be concatenated, not placed within quotes. Is TransactionLine.PrId a reference to form and textbox? Is TransactionLine name of form button is on? You named command button 'button'? Should use something less generic.

    Try:
    "[products].PrId = " & Me.PrId

    Is PrId a number datatype?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56
    Hi,
    TransactionLine is the Form based on table name transactionline
    Prid is the primary key from product table, transactionline.prid is the Foreign key..

    button is an event, i named it update inventory

    There is error highlighted on myrecorset.updatebatch.
    i guess there is the problem with the subtract. If i use for example myrecordset.Fields("CurrentStock") = Forms![transactionline].Quantity, where in logic dont work, the dlookup works fine, it gives me the available quantity.

    The problem is how to subtrack from the current quantity to the product table which host the stock

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Don't know, don't really understand your code and what you are trying to. I don't see any subtraction expressions in the code.

    Trying to maintain aggregate data in tables is problematic. Ideally, would enter stock in/out transaction records and calculate balances when needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56
    Hi June
    There is the form name TransactionLine, (order details)..

    I put product id, produt description, quantity(unbound).

    When i press the command button "update inventory" will take all the quantity for each productid and subtrack it from the stock table.

    i use this

    myrecordset.Fields("CurrentStock") = Forms![transactionline].Quantity - myrecordset.Fields("CurrentStock")

    But dont work..

    Regards

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Try:

    Me.CurrentStock = Me.CurrentStock - Me.Quantity
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56
    No this dont work

    Do you want me to give you the mdb?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    At this point, probably a good idea.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Sorry, I can't open rar files, only Windows Compression.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I opened TransactionLine form. I can see two buttons at bottom of form, both captioned in Greek. The right button has English name 'Close transactionline' so must be the left button is for 'Update inventory'. The Click event is set as Event Procedure, however, there is no VBA procedure with this button name. The only VBA procedure behind this form is a button click event but does not have name of either of these buttons. Perhaps if you correct name of button or the VBA procedure, this will work.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56
    Hi, if you open the transactionline it has all the data
    Try to open it from the main menu (the second button from the top).

    Thanos

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Data is not the issue, code is. The button has no code associated with it. Re-read my previous post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    thanosgr is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2012
    Posts
    56
    Hi June
    no work, i change the command button name... and gives me the same error
    highlighted

    myrecordset.MoveNext

    and says runtime error -2147217887 (80040e21)

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update records query...new to sql
    By hithere in forum Queries
    Replies: 6
    Last Post: 12-28-2011, 10:23 PM
  2. Update Multiple Records
    By anwaar in forum Programming
    Replies: 10
    Last Post: 09-02-2011, 05:16 PM
  3. Multiply front end on same computer?
    By efk0107 in forum Access
    Replies: 5
    Last Post: 01-25-2011, 08:39 AM
  4. How to Update 70,000++ Records
    By UCBFireCenter in forum Queries
    Replies: 54
    Last Post: 06-19-2009, 12:43 PM
  5. Replies: 3
    Last Post: 06-08-2009, 08:20 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