Why False?

  • Thread starter Thread starter Lee T.
  • Start date Start date
L

Lee T.

I am using InStr to validate what the user typed into a
particular field. Works okay but in the MSGBOX instead of
what I put in for the Prompt, I get FALSE. Here is what I
am using...

If InStr(1, [FNo], "-") = 0 Then
MsgBox Prompt = "Please enter - in your input",
vbokay, "Please Try Again!"

How can I override the FALSE prompt and put it what I want.

tia

LT
 
("apple" = "orange" ) results in FALSE

("orange" = "orange") results in true

(Prompt = "Please enter - in your input") results in false.

You like likey want:

Msgbox "Please enter - in your input"

or even better:

MsgBox Prompt "Please enter - in your input", vbExclamation, "Please Try
Again!"
 
Albert D. Kallal said:
("apple" = "orange" ) results in FALSE

("orange" = "orange") results in true

(Prompt = "Please enter - in your input") results in false.

You like likey want:

Msgbox "Please enter - in your input"

or even better:

MsgBox Prompt "Please enter - in your input", vbExclamation, "Please Try
Again!"

Looks like Prompt will be evaluated first and not likely give the flow the OP
wants... Maybe something like:

Dim s As String
s = InputBox("Please enter ""-"" in your input")
If InStr(1, s, "-") = 0 Then
MsgBox "Please enter ""-"" in your input", vbokay, "Please Try Again!"
End If
 
Although Albert and Mike gave you some good information, to answer your
*exact* question, you simply missed a colon.

When using named arguments instead of ordinal arguments, the syntax is
ArgName:=

You line should be:
MsgBox Prompt:= "Please enter - in your input", ...

Access was evaluating the expression:
prompt = "Please enter - in your input"

Because you don't have a Dim for a variable called "prompt," VBA created a
variable (variant) on the fly and compared it to your message text. Because
the variable "prompt" did not contain any text, the result of this
comparison was "False." Hence the message in your message box.

What a difference two tiny little dots can make!

Excuse me while I set Me.InstructorMode = True. :-)

This illustrates why it is *so* important to use Option Explicit in *every*
module. Had it been there, you would have gotten a "Compile error: Variable
not defined" message with the word "prompt" in your code highlighted. This
would have made the problem jump off the screen.

Me.InstructorMode = False

Good luck.

Sco
 
Albert,

Many Thanks! I always goof the msgbox and the MS
help is not all that helpful...

Lee T.
 
I am using InStr to validate what the user typed into a
particular field. Works okay but in the MSGBOX instead of
what I put in for the Prompt, I get FALSE. Here is what I
am using...

If InStr(1, [FNo], "-") = 0 Then
MsgBox Prompt = "Please enter - in your input",
vbokay, "Please Try Again!"

How can I override the FALSE prompt and put it what I want.

tia

LT

Your message is not clear to me.
Perhaps this is what you want.

MsgBox "Please enter - in your input", vbOKOnly, "Please Try Again!"
 
Back
Top