IF Then Else


B

Bill

Hi,
Can someone point out to me what I have wrong with this IF statement. No
matter what I change or where I place commas I still get a Syntax Error. I
have a Form with one text box for an input number and a command button to run
my query. I want to put in this IF statement in the query. It is suppose to
do this. When a number is put into the text box the query checks for match in
the dwFirstNumber field. If there is not any then to look in the
dwSecondNumber field and then the dwThirdNumber for matches. This is what I
entered on the criteria line of my query:
If(([Forms]![tblBoxed_Form]![Text0] = “dwFirstNumberâ€) then (“dwFirstNumberâ€))

Else
([Forms]![tblBoxed_Form]![Text0] = “dwSecondNumberâ€)

Else
([Forms]![tblBoxed_Form]![Text0] = “dwThirdNumberâ€)

Else
([Forms]![tblBoxed_Form]![Text0] = “â€) “Number Not Pickedâ€

End If

Just what I am I doing wrong? And what can I do to fix it. I want to thank
anyone who helps me out. I am just learning so I have to feel my way around
and ask some simple questions I should know.
Thanks,
Bill
 
Ad

Advertisements

J

John W. Vinson

Hi,
Can someone point out to me what I have wrong with this IF statement. No
matter what I change or where I place commas I still get a Syntax Error. I
have a Form with one text box for an input number and a command button to run
my query. I want to put in this IF statement in the query. It is suppose to
do this. When a number is put into the text box the query checks for match in
the dwFirstNumber field. If there is not any then to look in the
dwSecondNumber field and then the dwThirdNumber for matches. This is what I
entered on the criteria line of my query:
If(([Forms]![tblBoxed_Form]![Text0] = “dwFirstNumber”) then (“dwFirstNumber”))

Else
([Forms]![tblBoxed_Form]![Text0] = “dwSecondNumber”)

Else
([Forms]![tblBoxed_Form]![Text0] = “dwThirdNumber”)

Else
([Forms]![tblBoxed_Form]![Text0] = “”) “Number Not Picked”

End If

Just what I am I doing wrong? And what can I do to fix it. I want to thank
anyone who helps me out. I am just learning so I have to feel my way around
and ask some simple questions I should know.
Thanks,
Bill

Lots of things wrong here. For one thing, an IF/ELSE block works in VBA
program code; it doesn't work in a query.

In VBA, Else doesn't take arguments. An IF block is of the form

IF <true or false expression> THEN
<statements to execute if it is TRUE>
ELSE
<statements to execute if it is FALSE>
END IF

or, for a simple one-liner,

IF <true or false expressioni> THEN <single statement to run if true>

You're mixing these two and trying to multibranch as well.

Finally, your "statement to execute if true" isn't a statement, it's just a
text string. You can't execute a text string! What do you want to do with

Could you explain the context? What specifically do you want to happen?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top