Conditional If

S

Steve

How do I write the conditional If statement for a query criteria where if
Forms!MyForm!MyCbx = "AllCategories" then Like "*" else Forms!MyForm!MyCbx ?

I can't get the Like "*" to work.

Thanks!

Steve
 
J

John Smith

I do not think that you want the 'Like '*'" as that would return all records.
To get records that match the combo, unless the combo contains 'AllCategories'
you could use :-

SomeColumn = Forms!MyForm!MyCbx OR Forms!MyForm!MyCbx = "AllCategories"

as part of the query criteria. Don't forget to bracket it if you have other
criteria as well.
 
M

Michel Walsh

Hi,


Write a computed expression:

iif( Forms!MyForm!MyCbx = "AllCategories", True, Category LIKE
Forms!MyForm!MyCbx )


and set its criteria

<> false


Note that I assume the field you use for the comparison is named Category.


Hoping it may help,
Vanderghast, Access MVP
 
T

Tim Mills-Groninger

Steve said:
How do I write the conditional If statement for a query criteria where if
Forms!MyForm!MyCbx = "AllCategories" then Like "*" else Forms!MyForm!MyCbx
?

=Like iif(Forms!MyForm!MyCbx = "AllCategories", *, Forms!MyForm!MyCbx )
 
L

lucason

Steve said:
How do I write the conditional If statement for a query criteria where if
Forms!MyForm!MyCbx = "AllCategories" then Like "*" else Forms!MyForm!MyCbx ?

I can't get the Like "*" to work.

Thanks!

Steve



"Like "*"" has no meaning. Why bother with that criterium?

Anyway, where do you want to use the results of this query? In a form,
report, recordset?

Can't you just build the query in VBA before running it? (that's what
I would do)

Or you could use the filter property of the form or report. Set the
..filter, set the .filteron property to true, and voila.
 
P

Pavel Romashkin

LIKE iif(Forms!MyForm!MyCbx = "AllCategories", "*", Forms!MyForm!MyCbx)

Pavel
 

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