How do I use the Access OR and LIKE operators in an expression? L.

R

Richard Bancroft

How do you use the Access OR and LIKE operators in an expression. I want to
say " IIf field value equals 1 or 2 or 3 or 4 then..." If you were designing
a query in Access then you would put "In (1,2,3)" on the criteria line to get
this result. Why won't the same comma separator work in an expression?
 
G

Graham R Seach

Richard,

You can do this a few ways:
IIf([SomeField] < 5, ValueIfTrue, ValueIfFalse)

....or...

IIf([SomeField] = 1, ValueIfTrue, IIf([SomeField] = 2, ValueIfTrue,
IIf([SomeField] = 3, ValueIfTrue, IIf([SomeField] = 4, ValueIfTrue,
ValeIfFalse))))

....or...

Choose([SomeField], ValueIfOne, ValueIfTwo, ValueIfThree, ValueIfFour)

....or...

Switch([SomeField] = 1, ValueIfOne, [SomeField] = 2, ValueIfTwo,
[SomeFIeld] = 3, ValueIfThree, [SomeField] = 4, ValueIfFour)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
B

Brendan Reynolds

IN() works for me. For example, in the Control Source of a form text box ...

=IIf([SourceID] In (1,2,3),"123","not")
 
R

Richard Bancroft

Brendan,

thanks for that, I should have guessed that IN() would do it,

Richard Bancroft

Brendan Reynolds said:
IN() works for me. For example, in the Control Source of a form text box ...

=IIf([SourceID] In (1,2,3),"123","not")
--
Brendan Reynolds (MVP)


Richard Bancroft said:
How do you use the Access OR and LIKE operators in an expression. I want
to
say " IIf field value equals 1 or 2 or 3 or 4 then..." If you were
designing
a query in Access then you would put "In (1,2,3)" on the criteria line to
get
this result. Why won't the same comma separator work in an expression?
 
R

Richard Bancroft

Graham, many thanks for the suggestions. I've also had a suggestion to use
IN()) which works fine too,

Richard

Graham R Seach said:
Richard,

You can do this a few ways:
IIf([SomeField] < 5, ValueIfTrue, ValueIfFalse)

....or...

IIf([SomeField] = 1, ValueIfTrue, IIf([SomeField] = 2, ValueIfTrue,
IIf([SomeField] = 3, ValueIfTrue, IIf([SomeField] = 4, ValueIfTrue,
ValeIfFalse))))

....or...

Choose([SomeField], ValueIfOne, ValueIfTwo, ValueIfThree, ValueIfFour)

....or...

Switch([SomeField] = 1, ValueIfOne, [SomeField] = 2, ValueIfTwo,
[SomeFIeld] = 3, ValueIfThree, [SomeField] = 4, ValueIfFour)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

Richard Bancroft said:
How do you use the Access OR and LIKE operators in an expression. I want
to
say " IIf field value equals 1 or 2 or 3 or 4 then..." If you were
designing
a query in Access then you would put "In (1,2,3)" on the criteria line to
get
this result. Why won't the same comma separator work in an expression?
 

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