IIf statement within a IIf statement

A

Ana_T

Hi,



I have a report which has these parameters:



Vehicle A.

Km at sale date: 151.000

Km at actual date: 157.000

Dif_km: 6.000



Vehicle B.

Km at sale date: 78.000

Km at actual date: 94.000

Dif_km: 16.000



Fields from a query:

KM_sale

KM_actual

Dif_KM



I need to create an IF statement which would alert for the two following
conditions:



1. If at sale date the vehicle had less then 150.000 km then check the
difference between km and if it is less then 10.000 do nothing otherwise
show 'ALERT1'.

2. Is at sale date the vehicle has more then 150.000 km then check the
difference between km and if it is less then 5.000 do nothing otherwise
show 'ALERT2'

I tried the following expression with no avail.



=IIf([km_sale]<150000;IIf([dif_km]<10000;"";'ALERT1');IIf([dif_km]<5000;"";'ALERT2'))



Any help is appreciated.

TIA

Ana
 
W

Wayne Morgan

What did your expression give you? Also, sometimes reports get "picky" and
to use a field in an equation the field must be bound to a control on the
report first. (I believe it's an optimization feature, it only pulls the
fields it thinks it needs.) If that is the case, if you don't have km_sale
or dif_km bound to a control on the report, add a textbox for the field you
don't have bound and bind it to that field. Set the visible property of the
textbox to No so that it doesn't show.
 
O

OfficeDev18 via AccessMonster.com

Ana,

Yes, your IIf() can be made to work, but since you're checking for multiple
parameters it would be hard to do. More important, if any of the rules ever
change, you would have a hard time maintaining that line. If I were you I'd
do it in a simple manner.

Dim DispMsg As Integer

DispMsg = 0
If KM_Actual <= 150000 Then
If Dif_km > 10000 Then
DispMsg = 1
End If
Else
If Dif_km > 5000 Then
DispMsg = 2
End If
End If

If DispMsg = 1 Then
MsgBox Alert1..... (you can include more parameters here)
ElseIf DispMsg = 2 Then
MsgBox Alert2.....
Endif

More lines? No doubt. But is every line clear in its function? Then it's
ultimately maintainable.

Hope this helps,

Sam

Ana_T said:
Hi,

I have a report which has these parameters:

Vehicle A.

Km at sale date: 151.000

Km at actual date: 157.000

Dif_km: 6.000

Vehicle B.

Km at sale date: 78.000

Km at actual date: 94.000

Dif_km: 16.000

Fields from a query:

KM_sale

KM_actual

Dif_KM

I need to create an IF statement which would alert for the two following
conditions:

1. If at sale date the vehicle had less then 150.000 km then check the
difference between km and if it is less then 10.000 do nothing otherwise
show 'ALERT1'.

2. Is at sale date the vehicle has more then 150.000 km then check the
difference between km and if it is less then 5.000 do nothing otherwise
show 'ALERT2'

I tried the following expression with no avail.

=IIf([km_sale]<150000;IIf([dif_km]<10000;"";'ALERT1');IIf([dif_km]<5000;"";'ALERT2'))

Any help is appreciated.

TIA

Ana
 

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

Similar Threads


Top