How To Use The VBA Input Box Cancel Button To Exit Sub

Free MS Access VBA Programming Course

This post will demonstrate how you can use the VBA input box cancel button to
exit the sub procedure.

When you click the “Cancel” button on the input box, you return a null (blank) value, and
knowing this information, you can exit the sub procedure.

Here is an example:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Sub VBAInputBoxCancel()
    Dim strResponse As String
   
    strResponse = InputBox("Enter the Password To Continue", "Enter Credentials")
       
    'A clicked 'Cancel' button will result in a blank value
    If strResponse = "" Then
        MsgBox "You clicked the cancel button", vbInformation, "Bye"
        Exit Sub
    Else
        Select Case strResponse
            Case "Proc33d"
                MsgBox "Thank you"
            Case Else
                MsgBox "Wrong Password"
                Exit Sub
        End Select
    End If
End Sub

 

 

Any questions? We would love to hear your comment (s) below.

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

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: