Capturing an Error

C

cskgg

Hi all,

This forum is cool and provides superb suggestions - Welldone!!

My current problem:
I have included an "INPUTBOX" which gives me the option of inputting
search string. The choices offered are:
OK
and
CANCEL

If I click on CANCEL, the system gives "Runtime error 1004" dialogu
box.

What I wish to do is:
- if the user clicks on CANCEL, then display a message:
"Search cancelled by user".
- if the user does NOT enter any search string (i.e. leaves it
BLANK) but clicks on OK, then, display a message:
"Please input a search string" and display the initial
INPUTBOX again.

Thank you ever so much.
CSKG
 
P

Patrick Molloy

Sub GetSearchString()
Dim search As String
search = Trim(InputBox("Enter Search Text"))

If search = "" Then
MsgBox "Search Cancelled"
Else
' process the search string
End If

End Sub

hitting Cancel or clicking OK without entering any text
both result in the retun of an emoty string. So that's
your first test.

Patrick Molloy
Microsoft Excel MVP
 
Top