IIF statements with < or > signs

B

Burton

am trying to write a query in Access, but I am having problems. If I write
it like this:

IIf([Forms]![Form1]![Option22]=True,[Forms]![Form1]![Text6], "") than it
works just fine.

However, as soon as I add a > or < sign in the code, it stops working. This
is what I want it to say:

IIf([Forms]![Form1]![Option22]=True,>=[Forms]![Form1]![Text6], "").

Do you know why the > causes the query not to work? Do you know how I can
fix it?
 
D

Douglas J. Steele

You cannot change operators using IIf statements.

You need to tell the query always use >= [Forms]![Form1]![Text6], but only
when [Forms]![Form1]![Option22] is true.

That means your SQL will look something like:

WHERE (MyTable.MyField >= [Forms]![Form1]![Text6]
AND [Forms]![Form1]![Option22] = True)
 
D

Dirk Goldgar

Burton said:
am trying to write a query in Access, but I am having problems. If I write
it like this:

IIf([Forms]![Form1]![Option22]=True,[Forms]![Form1]![Text6], "") than it
works just fine.

However, as soon as I add a > or < sign in the code, it stops working.
This
is what I want it to say:

IIf([Forms]![Form1]![Option22]=True,>=[Forms]![Form1]![Text6], "").

Do you know why the > causes the query not to work? Do you know how I can
fix it?


It doesn't work because each argument of the IIf() function must be a value,
and ">=[Forms]![Form1]![Text6]" can't be interpreted as a value.

How exactly are you trying to use this expression? Are you putting it in a
criterion cell of the query? That's the only way I can make sense of it.
If that's the case, you *may* get what you're looking for with this:
=IIf([Forms]![Form1]![Option22]=True,[Forms]![Form1]![Text6], "")

But I don't know for sure. You'd have to explain in words what criteria
you're trying to apply to the query.
 
J

Jeff Boyce

Do you mean you want the literal characters ">=" to preceed the contents of
Form1!Text6?

Otherwise, recheck Access HELP for the syntax and examples of IIF().

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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