stupid question abt iif

V

Veli Izzet

Hi all,

I need to have a two level if statement.

To write with IIF syntax proves to be a tough job, so I wonder if there
is a way to write it in If-Then-Else If format in VBA and then convert
it to iif so that I will asign it to a control on a report.

Thanks for answers,
 
A

Arvin Meyer [MVP]

You can write it as a function or sub in VBA and use it directly in the
report, or write it as a public function and use it almost anywhere in
Access (including in queries). You can also use a Select Case statement if
there are several posibilities. You do not need to convert any functions,
merely use theree name in the report's property the same way that you'd use
IIF(), like:

=FunctionName(ArgumentIfThereIsOne)

But IIF is not that hard to use. A nested statement would take this form:

IIF([FieldToBeEvaluated] = Something, TruePart, IIF([FieldToBeEvaluated] =
Something, TruePart, FalsePart))
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
V

Veli Izzet

Thanks,

I know the syntax of IIF, however to keep track of (('s and ))'s seemed
too hard for this instance :)) The If - EndIF would be:

If HangiPara=1 Then

If HareketParaNew=1 Then
[Control]=Meblag
Else

If HareketParaNew=2 Then
[Control]=Meblag/UsdParite
Else
[Control]=Meblag/EuroParite
End If

Else

If HangiPara=2 Then

If HareketParaNew=1 Then
[Control]=Meblag*UsdParite
Else

If HareketParaNew=2 Then
[Control]=Meblag

Else
[Control]=Meblag/EuroUsd
End If
Else
If HareketParaNew=1 Then

[Control]=Meblag*EuroParite

Else

If HareketParaNew=2 Then

[Control]=Meblag*UsdEuro

Else
[Control]=Meblag
End If
End If


I'll try to write it bothways..
 
J

John Vinson

I know the syntax of IIF, however to keep track of (('s and ))'s seemed
too hard for this instance :))

The Switch() function can be handy in cases like this. It takes any
number of arguments in pairs; evaluates them left to right; and when
it first finds a pair where the first member is TRUE, returns the
second member of the pair.

John W. Vinson[MVP]
 
J

Judy Bauman

Veli Izzet said:
Thanks,

I know the syntax of IIF, however to keep track of (('s and ))'s seemed
too hard for this instance :)) The If - EndIF would be:

If HangiPara=1 Then

If HareketParaNew=1 Then
[Control]=Meblag
Else

If HareketParaNew=2 Then
[Control]=Meblag/UsdParite
Else
[Control]=Meblag/EuroParite
End If

Else

If HangiPara=2 Then

If HareketParaNew=1 Then
[Control]=Meblag*UsdParite
Else

If HareketParaNew=2 Then
[Control]=Meblag

Else
[Control]=Meblag/EuroUsd
End If
Else
If HareketParaNew=1 Then

[Control]=Meblag*EuroParite

Else

If HareketParaNew=2 Then

[Control]=Meblag*UsdEuro

Else
[Control]=Meblag
End If
End If


I'll try to write it bothways..

You can write it as a function or sub in VBA and use it directly in the
report, or write it as a public function and use it almost anywhere in
Access (including in queries). You can also use a Select Case statement
if
there are several posibilities. You do not need to convert any functions,
merely use theree name in the report's property the same way that you'd
use
IIF(), like:

=FunctionName(ArgumentIfThereIsOne)

But IIF is not that hard to use. A nested statement would take this form:

IIF([FieldToBeEvaluated] = Something, TruePart, IIF([FieldToBeEvaluated]
=
Something, TruePart, FalsePart))
 
Top