This posting is "short and sweet" as I think the below code snippet is self-explanatory (even though the StrPtr function may be new to you)...
Simply replace the MsgBoxes with any code you might want to execute for the stated outcome. To get a better feel for what is going on, copy/paste the above code into a general Module (Insert/Module from the VB editor menu bar) and run it.... first click the OK button without entering anything, then type something in and click the OK button, then finally click the Cancel button (with or without text in the type-in field).Code:Sub TestMe() Dim Answer As String '.... '.... Answer = InputBox("Tell me something") If StrPtr(Answer) = 0 Then MsgBox "The user clicked Cancel, so we will exit the subroutine now." Exit Sub ElseIf Len(Answer) = 0 Then MsgBox "The user clicked OK without entering anything in the InputBox!" Else MsgBox "The user entered the following..." & vbLf & vbLf & Answer End If '.... '.... End Sub
Bookmarks