Link to home
Start Free TrialLog in
Avatar of fcp
fcp

asked on

Input box problem

How can i know if a user answer an Inputbox with the "CANCEL" button or with the "OK" button but with a "" string?
Avatar of Vbmaster
Vbmaster

You create a form and make it look just like the standard inputbox, and use that form.. this is probably the easiest way of doing it.
Try this:

Dim s_text As String

s_text = "" & InputBox("Enter your response", "Data Entry", "")

If s_text = "" Then
    MsgBox "Invalid Entry"
End If

The third parameter on the Inputbox is the default value. If the user cancels the Inputbox, it will be set to "", if they just press OK with nothing in the Inputbox, it will be set to "". If they type in a space or at least one character, it will not display the error in my code.

The first parameter in an input box is the prompt on the Inputbox, the second is the title on the Inputbox.

Does this help?
You can set the default for the inputbox (third parameter) to a space.

Dim x
x = InputBox("input something", , " ")

If 'ok' is selected then " " is returned. If 'cancel' is selected then "" is returned. You can distinguish the button that was pressed this way. However, I think VBmaster's solution is the better way to go. I rarely use the inputbox to retrieve user input. More professional and versatile to create your own.
Avatar of fcp

ASKER

For Cable:
Sorry, but your code is not the solution: if the user click "CANCEL" or
"OK" with a empty string, it make the same thing.

For VBMaster and JGV:
I also like create forms to get user-input data, but for some strange "BOSS" reasons -and the boss is NOT a programmer :( - i prefere to use the inputbox. Maybe there is no answer for my question, i dont know...
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fcp

ASKER

As what i suspect, no way...
....maybe Subclassing? (yes, is more simple a custom form, is only for knowledge...)
Avatar of fcp

ASKER

Oh, i close question without care: vbmaster is the first that says "no way". How i can remedy my fault?
Maybe you can post a question asking if they can do that at the customer service section..

https://www.experts-exchange.com/Customer_Service/Experts_Exchange/

I think they will be happy to help you out, at least I heard people getting really fast reponse from them.
Avatar of fcp

ASKER

mmm... better i pose a "Fake" question for you, vbmaster.