"IF" formula in a query

P

Phil

Well,

What do you want to use "If" for?
In order for us to help you, more examples will be required.

Phil
 
F

fredg

hi
i need to use the IF formula in a ms-access query. Please help.

Reg
Deepak

You cannot use If .. Then directly in a query.
You can create a User Defined function using If and then call it from
the query:
Public Function SomeFunction(TextIn)
Dim Result as String
If TextIn = "Good" Then
Result = "Great Job"
ElseIf TextIn = "Bad" Then
Result = "Try Harder"
Else
Result = "You're doing well"
End If
SomeFunction = result
End Function

In the query, use:
Exp:SomeFunction([FieldName])

However, you can use the Immediate If ... IIf() directly in a query:

Exp:IIf([SomeField]="Good","Great Job", "IIf([Somefield]= "Bad","Try
Harder","You're doing well"))
 
Top