Results 1 to 5 of 5
  1. #1
    saudkazia is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Location
    India
    Posts
    71

    Delete transactions and return stock when canceling order - Northwind Database

    I have built my Database from the Northwind database. One gaping problem is that cancelled order doesn't return stock. I tried to fix this my modifying the delete vba entry but for some reason it doesn't want to delete the order details or transactions.

    Here is what I tried to use -



    Dim rsw As New RecordSetWrapper
    If rsw.OpenRecordset("inventory transactions", "[Customer Order ID] = " & OrderID) Then
    Delete = rsw.Delete
    ElseIf rsw.OpenRecordset("order details", "[Order ID] = " & OrderID) Then
    Delete = rsw.Delete
    ElseIf rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
    Delete = rsw.Delete
    End If

    What am I doing wong.

  2. #2
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    https://msdn.microsoft.com/en-us/lib...or=-2147217396
    I haven't done this and the microsoft website doesn't show it, but you do have to do an update after you've changed data using dao.rs.
    The MS site does a movenext which automatically does an update.
    Try an rsw.update after the delete and if that doesn't fix the problem, see if the MS site can help.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Please tell us more about RecordSetWrapper.

    As for the Cancelled Order, I would have expected you would be required to Cancel the order, then return all items and quantities to the Items/Products table. It could be automated, but you would do it in some code attached to an event.

    Just as you add items to an Order, or update stock when you receive Product from Supplier, I would think returning stock to Items/Products would be code you write --- for Cancelled Orders or Item Returns.

  4. #4
    saudkazia is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2015
    Location
    India
    Posts
    71
    RecordSetWrapper is a SQL Recordset automation function in Northwind Database. I understood the issue after .movenext from JamesDeckert.

    This worked perfectly.

    Dim rsw As New RecordSetWrapper

    Code:
     If rsw.OpenRecordset("order details", "[Order ID] = " & OrderID) Then
            With rsw.Recordset
                If Not .EOF Then
                    Do While Not .EOF
                       Delete = rsw.Delete
                        
                        .MoveNext
                    Loop
                End If
            End With
        End If
        If rsw.OpenRecordset("Inventory Transactions", "[Customer Order ID] = " & OrderID) Then
            With rsw.Recordset
                If Not .EOF Then
                    Do While Not .EOF
                     Delete = rsw.Delete
                        
                        .MoveNext
                    Loop
                End If
            End With
        End If
        Set rsw = Nothing
        
    
    
          If rsw.OpenRecordset("Orders", "[Order ID] = " & OrderID) Then
            Delete = rsw.Delete
        End If
    Basically the problem was that the current rsw would delete only one record that matched. We need to to do a loop of all the matching records and delete them.

    This site helped in the syntax for recordsetwrapper - https://github.com/jamiewest/VBA-Lib...cordsetWrapper

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

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

Similar Threads

  1. northwind order details form 2010
    By betna in forum Forms
    Replies: 9
    Last Post: 07-26-2015, 06:24 PM
  2. Replies: 4
    Last Post: 11-21-2013, 12:25 PM
  3. Replies: 2
    Last Post: 10-01-2012, 06:47 PM
  4. Design multi user database - avoid simultaneity transactions
    By snoopy2003 in forum Database Design
    Replies: 2
    Last Post: 02-27-2011, 12:03 AM
  5. Northwind Purchase Order Number
    By jpl85716 in forum Access
    Replies: 3
    Last Post: 09-29-2010, 12:53 PM

Tags for this Thread

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