Conditional If

  • Thread starter Thread starter Steve
  • Start date Start date
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
 
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.
 
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
 
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 )
 
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.
 
Back
Top