Access - VBYesNo to Void Transactions in a Do Loop

Posted on 2012-09-05
Last Modified: 2012-09-05
Well, I figured I'd end up with this as a question.  I wanted to insure that if a clerk selected a command button on a form that opens a 2nd Form and then decides "Oops, I didn't want to do that" That the Cancel command button would VOID the transactions that were INSERT INTO the db when selecting the first Form's Command Button.   (Just FYI - when they select a command button on the first form it inserts a Set number of new records into the Db)

When the 2nd form opens it only shows the x number of new records that form1 created.  There the user is supposed to input info for each of the new records created.   If they choose to cancel I have to have those transactions voided due to what is going to happen elsewhere in the program.

The VBYesNo function I set up to cancel doesn't work it keeps going to the Else portion regardless of whether the user selects yes or no.....

Private Sub cmdCancel_Click()
Dim z As Integer
z = 1

If MsgBox("You selected CANCEL.  This will delete the current information.  Are you sure you want to Cancel the input of this information?", vbYesNo, "CANCEL INFORMATION!") = vbOK Then
        CurrentDb.Execute "Update ShiftReportingLVL set Voided=Yes" _
            & " WHERE RptgSeqID=" & Me.txtMaxSeqID & " And LVLPositionNbr =" & z, dbFailOnError
        z = z + 1
        If z = Val(Me.txtLocationNbrMachines) + 1 Then Exit Do
    MsgBox "This LVL Reporting information has been voided.  If you still need to record an LVL Reporting you must re-execute the LVL Reporting Main Menu!", vbOKOnly, "NOTICE! LVL REPORTING VOIDED!"
    MsgBox "You chose to Exit the Cancel function." & vbNewLine & vbNewLine & "Please review the information input.  If your input is complete you must choose either:" & vbNewLine & _
    "i)Save & Close OR ii)Cancel", vbOKOnly, "EXIT THE CANCEL LVL REPORTING PROCEDURE!"
End If

End Sub

Open in new window

Any help on what I have out of order or syntaxed incorrectly?
Question by:wlwebb
    LVL 39

    Accepted Solution

    Try to change vbOK to vbYes, they have different values

    Author Closing Comment

    UUUgggghhhh!!!!!!!!  Thanks!!!!!!

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now