if function

A

angie

how can i use the if function in access? can i also create nested functions?

could you give me an example?
 
K

K Dales

There is the native Access Iif function (immediate If)
that you can use in expressions, then there is the VBA IF
statement you can use in writing your own functions. Both
can be nested.

For the Iif Function:

=Iif([CODE1]="A","X",Iif([CODE2]="B","Y","Z"))

This checks the field CODE1 and if it is A results in the
value X. If not, it then checks CODE2 and if CODE2 is B
sets the result to Y. If neither of the conditions is
true it sets the result to Z.

For VBA code:

Function IFDEMO(Code1 as String, Code2 as String) As String

IF Code1 = "A" Then
IFDEMO = "X"
Else
If Code2 = "B" Then
IFDEMO = "Y"
Else
IFDEMO = "Z"
End If
End If

End Function

This uses variables instead of field values, but the logic
is the same.

HTH...
K Dales
 

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