IIf Statement

DBL

Registered User.
Local time
Today, 19:16
Joined
Feb 20, 2002
Messages
659
Is there a better way to do this as it's not giving me the right results - so maybe I should say a correct way to do this!

=IIf([PMtype]="3" Or "4" Or "5",2,1)

Thanks

DBL
 
i think there's a way with IIf but something like this should work too:
Code:
Private Sub Text0_AfterUpdate()

    Select Case Me.Text0.Value
        Case 3, 4, 5
            MsgBox "2"
        Case Else
            MsgBox "1"
    End Select

End Sub
 
I'm trying to show results in a report so I put that in the control of an unbound text box to get either 2 or 1, I then sum the number at the bottom. Don't know if that makes a difference.

D
 
=IIf(([PMtype]="3") Or ([PMtype]="4") Or ([PMtype]="5"),2,1)

???
 
There may be better way, but this is my 2 pence worth;

Put this in the query that is the source for your form, thenuse Result as the control source for an unbound control on the form.

Code:
Result: IIf([PMType]=3,2,IIf([PMType]=5,2,IIf([PMType]=4,2,1)))

or

Code:
Private Sub PMType_AfterUpdate()
    Select Case PMType
        Case 3, 4, 5
            Me.txtCode = 2
        Case Else
            Me.txtCode = 1
    End Select
End Sub
 
If [PMType] truely is a text field (as implied by your original post), then what Ken said...
=IIf(([PMtype]="3") Or ([PMtype]="4") Or ([PMtype]="5"),2,1)

If it is actually a numeric field type, you would need to omit the quotes...
=IIf(([PMtype]=3) Or ([PMtype]=4) Or ([PMtype]=5),2,1)
 
Here is the easiest way....

=IIf([PMtype]=in("3","4","5"),2,1)

Note: If the data type of PMtype is not a text, then loose the quotes.
 
bvan said:
=IIf([PMtype]=in("3","4","5"),2,1)

Note: If the data type of PMtype is not a text, then loose the quotes.

Hum, Didn't think of that. Thanks :)
 
Thanks very much indeed. Will try it out tomorrow and hopefully get it fixed - and, yes, it's a number field, sorry!

D
 

Users who are viewing this thread

Back
Top Bottom