Capturing an Error

  • Thread starter Thread starter cskgg
  • Start date Start date
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top