IIF / OR - Multiple conditions based on multiple fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want the OnPrint of a report to check three fields and run code if any ONE
of the conditions is met:

Iif ([MyTextOne]=1 OR [MyTextTwo]=2 OR [MyTextThree]=3) Then
RunSomeCode
Else
RunOtherCode

I thought of using Select Case and calling procedures as each condition is
met:

Select Case Me![MyTextOne]
Case is = 1
Call Check2
Case else
Stop
End Select

Check2 ()
Select Case Me![MyTextTwo]
Case is = 2
Call Check3
Case else
Stop
End select

Check3 ()
and so on.........


It will work, but gets a bit too long as the test conditions increase. It
gets just as long with nested select case or nested IIf.
 
The first line of code (with the OR conditions) is probably the best if you
only have 2 lots of code to choose between.

If you have lots of OR conditions, there's a very good chance that the
problem is with the data structure. Instead of lots of repeating fields, you
might want to consider whether it would be better to use a related table
with a *record* for each, in place of the many fields for the options.
 
Thanks for the response.

I thnk the scenario might add some value to my question.

The data on-screen is sent to to an external file as soon as three
conditions are met. The export is done with a command button. The conditions
to be met are specific values in three fields. I am trying to prevent the
users from exporting data which does not meet the required conditions and
alert them with a message that they should check the three fields.

Alternatively, I will use the same process to discable the command button
until the three conditions are met.

A clumsy work around, but here's what I have done in the meantime:

An unbound MyTextBoxCheck on the form with control source
[MyTextOne]&[MyTextTwo]&[MyTextThree]. An IIf statement checks for an exact
match in the MyTextBoxCheck and runs appropriate code.

Those of us who don't know must work a little harder! :)

Thanks to your site and others like yours, it's been a while since I've had
serious problems as a result of data structure.
 
Back
Top