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
    Else
        MsgBox "Cancel"
    End If

End Sub

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




By the way, if you got or are getting value from the VBA information, please give me a tip, thanks!


These posts may help answer your question too...

How To Make An InputBox In VBA

The input box is a great way to retrieve and process input from your user. In the following example we’ll control program flow based on the user’s input in the inputbox. Your user will enter a text value and we will evaluate their answer and send them in the right direction. Sub InputboxVBA() Dim strAnswer […]

Previous Post

How To Add A MS Access Custom Ribbon

Next Post

Video: Access report parameter with date range