ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Input box question (https://www.excelbanter.com/excel-programming/422037-input-box-question.html)

JT

Input box question
 
I'm using the following code to capture the user entered Group ID:

vGp = Trim(InputBox("Enter Group ID or ""All"", "Customer Group"))

The input form has an OK and Cancel Button. The problem is vGP returns ""
if the user presses OK and does not enter anything or if they press the
Cancel button.

Is there a way to determine which button was pushed? The reason is I will
take different actions depending on which button was pushed.

Thanks for the help......

--
JT

Mike H

Input box question
 
Hi,

You could test for a null string

Sub sonic()
vGp = Trim(InputBox("Enter Group ID or All", "Customer Group"))
If vGp = vbNullString Then
'do something
MsgBox "Nullstring"
Else
'Do something else
End If
End Sub


"JT" wrote:

I'm using the following code to capture the user entered Group ID:

vGp = Trim(InputBox("Enter Group ID or ""All"", "Customer Group"))

The input form has an OK and Cancel Button. The problem is vGP returns ""
if the user presses OK and does not enter anything or if they press the
Cancel button.

Is there a way to determine which button was pushed? The reason is I will
take different actions depending on which button was pushed.

Thanks for the help......

--
JT


JLGWhiz

Input box question
 
If you use the InputBox Method then the Cancel will equal False and can be
distinguished from the OK with a blank entry.



"JT" wrote:

I'm using the following code to capture the user entered Group ID:

vGp = Trim(InputBox("Enter Group ID or ""All"", "Customer Group"))

The input form has an OK and Cancel Button. The problem is vGP returns ""
if the user presses OK and does not enter anything or if they press the
Cancel button.

Is there a way to determine which button was pushed? The reason is I will
take different actions depending on which button was pushed.

Thanks for the help......

--
JT


Harald Staff[_2_]

Input box question
 
Hi JT

Remove Trim from the inputbox and try this:

Sub test()
Dim vGp As String
vGp = InputBox("Enter Group ID or ""All""", "Customer Group")
If StrPtr(vGp) = 0 Then
MsgBox "Cancel button"
End If
vGp = Trim(vGp)
End Sub

HTH. Best wishes Harald

"JT" wrote in message
...
I'm using the following code to capture the user entered Group ID:

vGp = Trim(InputBox("Enter Group ID or ""All"", "Customer Group"))

The input form has an OK and Cancel Button. The problem is vGP returns ""
if the user presses OK and does not enter anything or if they press the
Cancel button.

Is there a way to determine which button was pushed? The reason is I will
take different actions depending on which button was pushed.

Thanks for the help......

--
JT




All times are GMT +1. The time now is 12:26 PM.

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