PDA

View Full Version : Inputbox STATEMENT



fadib
01-23-2008, 10:27 AM
Hi guys,
I have a question concerning inputbox.
how can I refer to the cancel button in the inputbox.
What I am trying to accompish is this:
if the user click on the cancel button, I want it to exit the sub. (I think it is a debug issue) :banghead:

Carl A
01-23-2008, 11:10 AM
If the cancel button is selected it returns an empty string so test for an empty string using your input box variable.

if MyValue = "" then exit sub
In the help files search for InputBox Function for more info

fadib
01-23-2008, 12:01 PM
Sweet Thanks Carl!!!! Two thumbs up

mikerickson
01-23-2008, 01:06 PM
This distiguishes between a user entering "" and the user pressing Cancel.

Dim Reply As String

Reply = InputBox("Enter something")

If StrPtr(Reply) = 0 Then
MsgBox "You pressed Cancel."
Else
If Reply = vbNullString Then
MsgBox "You entered nothing and pressed OK."
Else
MsgBox "You entered " & Reply
End If
End If

The InputBox function (above) is limited to returning a String.


The InputBox Method (Application.InputBox) allows more kinds of return value. It shows "Cancel Pressed" by returning FALSE.