How To Determine If A User Clicked The Cancel Button On VBA Input Box

In this post I am going to address the question:

“How can I determine if a user clicked the cancel button on a VBA Input Box”

I only need to check the length of the InputBox response. If the “Cancel” button was clicked,
the variable containing the value of the InputBox will be zero.

In the following code I am entering the name of the arguments which allows me to place the
arguments out of order:

Sub VBAInputboxCancel()
    Dim strDigPermit As String
    strDigPermit = InputBox(Prompt:="Enter the Dig Permit Number", Title:="Dig Permit", Default:="0")
    If Len(strDigPermit) Then
        MsgBox strDigPermit
        MsgBox "Cancel"
    End If

End Sub

Hope this helps. If you have any specific questions, contact me here.

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