On Tue, 25 Oct 2005 17:27:03 -0700, Brook wrote:
good day Fredg,
Thanks for the quick response..
I think the best bet for me would be to call a function...
Do I just code the if then else statement in standard if then else coding?
how do I call the function? and when you say funtion.. do you mean module?
Thanks,
Brook
:
On Tue, 25 Oct 2005 16:51:03 -0700, Brook wrote:
Good day all...
Is it possible to create a compound IF Statement in Access Query?
For example... I want to set up a statement similar to :
If X, then
XX
Else If Y, then
YY
Is this possible?
Thanks,
Brook
What if it's neither X nor Y?
Directly in an Access Query, you can use the IIf() function.
Exp:IIf([FieldA]="X","Show This",IIf([FieldA] = "Y","Show this
instead","Neither X nor Y"))
If you have a more complicated If Then you can use If.. Then.. Else in
a Public Function in a Module.
Simply call the function from the query:
Exp
oThisFunction([FieldName])
There are additional functions that you can also use, such as (in the
query) Choose, Switch and (in a public function) Select Case.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Click on Modules + New
Click on Insert + Procedure
Enter SomeName in the Name box.
Select the Function check box
Click ok
Type your function between the 2 existing lines.
Something like this:
Public Function SomeName(StringIn as string) as String
Dim strNew as String
If StringIn = "X" Then
strNew = "This"
ElseIf StringIn = "Y" then
strNew = "That"
ElseIf StringIn = "Z" Then
strNew = "This and That"
Else
srtNew = "None of the above"
End If
SomeName = strNew
End Function
Save the function.
When prompted, name the new module anything except SomeName.
Call if from a query and pass it the name of the field to be used in
the function.
Exp:SomeName([FieldA])
You'll probably also want to add error handling as needed.