Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    robsworld78 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    181
    Well, I'm happy I figured it out. Not the cleanest solution but its what I came up with and it works.



    Since my original code did work and just didn't do all the records I thought about playing with GoToRecord and SetFocus. Now I have it so the 2nd subform setsfocus and goes to first record, then the SQL update I have gets run, then it goes to next record and the update is run again, then to next record and so on. Of course it does nothing when it focuses on a record not in the new order and continues so that's good. Once it goes through all the records on subform 2 it runs an SQL update which comes from a query. I was able to make 3 queries, one has all the records from the 1st subform and the 2nd query has all the records from the 2nd subform, then on the 3rd query it only shows the records not on the 1st subform and inserts those remaining records.

    Its all invisible and instant, I'm very happy it's working. Thanks for you help if you have any suggestions to improve this let me know. Here's the code.

    Code:
    Dim rs As DAO.Recordset
    Set rs = Me.RecordsetClone
    
    Forms!CreateOrders!CreateOrdersVansSetForTransfer.SetFocus
    Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!VendorID.SetFocus
    On Error Resume Next
    DoCmd.GoToRecord , , acFirst
    DoCmd.SetWarnings False
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    On Error Resume Next
    DoCmd.GoToRecord , , acNext
    
    DoCmd.RunSQL "UPDATE Inventory SET BarsGivenVan=" & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!BarsLeft & _
    " WHERE OrderID = " & Forms!CreateOrders!OrdersOrdersSubform.Form!OrderID & "  And Product = " & Forms!CreateOrders!CreateOrdersVansSetForTransfer.Form!ProductID
    
    DoCmd.RunSQL "INSERT INTO Inventory (Product, OrderID, BarsGivenVan) " & _
    "SELECT ProductID, " & [Forms]![CreateOrders]![OrdersOrdersSubform]![OrderID] & " AS OrderID, " & "BarsLeft " & _
    "FROM CreateOrdersVanTransferAppendQueryMain "
    DoCmd.SetWarnings True
    
    Me.Requery

  2. #17
    robsworld78 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Posts
    181
    Anyone know how I would add some better Error handle code to this.

    Of course once it gets to the end of the records it pops up an error saying "no more records or whatever" but with "On Error Resume Next" it does continue through all the code without flashing an error however it would be nice when it hits the first error it stops processing the code and continues processing again once it gets to the SQL update near the end of the code, is that possible?

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

Similar Threads

  1. Update Multiple Records
    By anwaar in forum Programming
    Replies: 10
    Last Post: 09-02-2011, 05:16 PM
  2. Update multiple records at once
    By ariklewis in forum Queries
    Replies: 6
    Last Post: 06-13-2011, 02:33 PM
  3. Update Multiple fields according multiple criterias
    By denis.m in forum Programming
    Replies: 1
    Last Post: 02-21-2011, 11:03 AM
  4. Update dates for multiple (not all) records
    By thekruser in forum Access
    Replies: 2
    Last Post: 08-30-2010, 05:27 PM
  5. Replies: 1
    Last Post: 12-10-2009, 08:41 PM

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