Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to distinguish between cancel and ok with inputbox 5

Status
Not open for further replies.

Painkiller

Programmer
May 18, 2001
97
NL
Hi all,

Some time ago I found some code that showed a method that made it possible to find out wether a user pressed 'cancel' or just typed nothing and pressed 'Ok' with an inputbox. Problem is, I can't find the code anymore, and I need it now!

Anybody outthere that knows how to solve this problem?

Much appreciated,

Sujesh
 
Sujesh,
You can use an if statement like the following to check to see what button the user pushed. You can use the .caption or .text properties of the message box to see if the user typed anything in or not.

If MsgBox(strMsg, vbOKCancel, "Error!") = vbOK Then

Go here to see all the possible values that msgbox can return. (vbOK,bcCancel,etc.)

Hope this helps,
Kevin
 
You can also do it this way:

[red] Dim BoxVar As String
BoxVar = MsgBox("Are you sure?", vbOKCancel)
If (BoxVar = vbOK) Then
MsgBox "Done!"
Else
MsgBox "Cancelled!"
End If[/red]

Brett Please visit my websites!
 
Sujesh --

Your question is about InputBox, not MsgBox...right?

InputBox returns a string. If you click [OK] or just press [Enter], then InputBox returns whatever was entered in the textbox. If you click [Cancel], then the returned string will be empty ("").

WB



 
Thanks guys for all your replies, the last last reply was actually the one I was looking for (INPUTbox, user types nothing). THanks ktighe!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top