Inputbox Cancellation

  • Thread starter Thread starter Michelle
  • Start date Start date
M

Michelle

Tried several suggestions, but nothing seems to give me
the result I want. Basically I have a group of fields I
want to fill with the result of data gathered from an
Inputbox. Sometimes the response will exist, other times
users may cancel. I am currently unable to determine when
the cancel button has been pressed from the Inputbox
dialog. I can determine that the value assigned to the
inputbox is blank, but that's an okay condition if the
user doesn't want to change the data already in the cell,
so I need to be able to determine what's a conscious
omission versus the press of a cancel button. Any ideas?

Many thanks
 
Michelle,

Try something like the following:

Dim S As String
S = InputBox("Enter something")
If S = "" Then
If StrPtr(S) = 0 Then
MsgBox "User clicked cancel"
Else
MsgBox "User entered empty string"
End If
Else
MsgBox "User entered: " & S
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Brilliant! Worked like a charm. But what DOES StrPtr
really do? I couldn't find it in the help files.

Thanks much!!
 
Michelle,

StrPtr is not supported by Microsoft, but it is available along
with its cousins VarPtr and ObjPtr. Basically, it returns the
memory address to which the string variable S points. When the
string contents are entirely unallocated, S points to 0. When S
contains any string, including a 0 length empty string, StrPtr
returns a positive memory address location.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top