Simple Iff statement problem

Joe8915

Registered User.
Local time
Yesterday, 17:02
Joined
Sep 9, 2002
Messages
820
I have a field called Invoice Number. If the Invoice Number contains the word final, then display a MsgBox "do something"
this is what I have so far.

Private Sub Invoice_Number_AfterUpdate()
IIf = (Invoice_Number) <> "final"
MsgBox ("then do something")
End Sub

Of course I get a error. Where did I go wrong?
 
IIF's are usually used in queries and control sources. IF statements are used in VBA.

Code:
Private Sub Invoice_Number_AfterUpdate()
   If Instr(1, Me.Invoice_Number, "final") > 0 Then
      MsgBox ("then do something")
   End If
End Sub
 
I have a field called Invoice Number. If the Invoice Number contains the word final, then display a MsgBox "do something"
this is what I have so far.

Private Sub Invoice_Number_AfterUpdate()
IIf = (Invoice_Number) <> "final"
MsgBox ("then do something")
End Sub

Of course I get a error. Where did I go wrong?

IIf can't be used in VBA code blocks. You'll need to use VBA for that. Here's the code you want:

Code:
IF txtInvoiceNumber <> "final" Then
    msgbox("text here")
END IF

If you're trying to do this in a control's Datasource property, then, yes, use IIf:

Code:
IIf ("final","text here",[txtInvoiceNumber])

the way IIf works:

IIF ([enter logic that will either be true or false], [do this if it's true], [do this if it's false])
 
IIf can't be used in VBA code blocks.
Not quite true. They can be used. It just isn't efficient since it checks both the true and false whereas the IF statement will stop checking when something matches.
 
IIF's are usually used in queries and control sources. IF statements are used in VBA.

Code:
Private Sub Invoice_Number_AfterUpdate()
   If Instr(1, Me.Invoice_Number, "final") > 0 Then
      MsgBox ("then do something")
   End If
End Sub

It work like a charm
Thanks Bob
 

Users who are viewing this thread

Back
Top Bottom