"IF" formula in a query

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Well,

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

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

Reg
Deepak
 
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"))
 

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

Back
Top