ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inputbox Cancellation (https://www.excelbanter.com/excel-programming/283887-inputbox-cancellation.html)

Michelle

Inputbox Cancellation
 
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

Chip Pearson[_2_]

Inputbox Cancellation
 
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


"Michelle" wrote in message
...
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

Inputbox Cancellation
 
Brilliant! Worked like a charm. But what DOES StrPtr
really do? I couldn't find it in the help files.

Thanks much!!

-----Original Message-----
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


"Michelle" wrote in

message
...
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



.


Chip Pearson[_2_]

Inputbox Cancellation
 
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


"Michelle" wrote in message
...
Brilliant! Worked like a charm. But what DOES StrPtr
really do? I couldn't find it in the help files.

Thanks much!!

-----Original Message-----
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


"Michelle" wrote in

message
...
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



.





All times are GMT +1. The time now is 07:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com