How To Make A VBA Message Box OK Cancel

Ever wonder how you can create a vba message box to gather “ok” and “cancel” answers?

This is useful when you want a user to provide confirmation for a delete procedure or other long running process.

When you want to gather feedback from the user do something like this:

Sub VBAMessageBoxOkCancel()
    Dim intAnswer As Integer
    'here is where your answer from the user is held
    intAnswer = MsgBox("Are you sure?", vbOKCancel, "Please Confirm")
    Select Case intAnswer
        Case vbOK
            MsgBox "Continuing..."
        Case vbCancel
            'exit the procedure
            Exit Sub
    End Select
End Sub

Here’s a short video:


Let me know if you have any questions.

Offsite Related Information:

“Go Fund Me” Page

($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Tags: , ,