• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 125
  • Last Modified:

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?
0
fcp
Asked:
fcp
1 Solution
 
VbmasterCommented:
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.
0
 
cable4096Commented:
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?
0
 
jgvCommented:
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.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
fcpAuthor Commented:
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...
0
 
mcriderCommented:
This is a direct quote from the InputBox Help Page:

"If the user clicks OK or presses ENTER, the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string ("")."

The only thing you can do is check to see if the returned string is "" or Len(string)=0

This is a limitation of using the InputBox... Therefore, if an InputBox has an initial value, and the user deletes all of the characters out of the InputBox and presses "OK" this is the same as pressing the "Cancel" button and your program should treat it this way.

If you don't want to work with this limitation, you must build your own form.


Cheers!
0
 
fcpAuthor Commented:
As what i suspect, no way...
....maybe Subclassing? (yes, is more simple a custom form, is only for knowledge...)
0
 
fcpAuthor Commented:
Oh, i close question without care: vbmaster is the first that says "no way". How i can remedy my fault?
0
 
VbmasterCommented:
Maybe you can post a question asking if they can do that at the customer service section..

http://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.
0
 
fcpAuthor Commented:
mmm... better i pose a "Fake" question for you, vbmaster.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now