Conditional Message Box

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

I want to do a couple of things, first, compare data input in a text field
against a stored value. Second, if the values equal, display a message box,
if they don't equal display a different message box.

Can anyone point me in the right direction?

Thanks!
 
Customize by what your stored value is:

dim Resp as integer

Resp = InputBox("Enter 1 to display MsgBox 1 or enter 2 to display MsgBox 2")

if Resp = 1 then
MsgBox "You entered 1.", vbOKOnly (or whatever style you like)
else
MsgBox "You entered 2.", vbOKOnly
end if

This does not do anything for values other than those for which you
prompted; i.e., you will always get the second message box if the user enters
something other than 1. To modify...

if Resp = 1 then
MsgBox "You entered 1.", vbOKOnly (or whatever style you like)
elseif Resp = 2 then
MsgBox "You entered 2.", vbOKOnly
else
MsgBox "You did not enter a correct value.", vbOKOnly
end if

This latter set up is good if you are calling a function or setting forth a
process. If the user enters something other than 1 or 2, you can cancel
events, perform undos/clean-ups, etc.

To use in your scenario, rather than checking Resp against 1 or 2, you would
check the user's input against your stored value.

HTH.

Ross
 
Back
Top