iif syntax error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

A2K2
i'm trying to get a cbo (drop-down value list) on a form to open another
form and go to a specific field if the choice selected is "1", or go to the
next field of the original form if the choice selected is "0".
here's my code i put in the OnChange event:
IIF("FieldName"=1, (DoCmd.OpenForm "Form2", acNormal,,,acFormAdd,
acWindowNormal) (DoCmd.GoToControl "FieldName2"), 0)
it might just be the hangover, but i don't see what's missing.
thanks everyone
 
Joe Mills said:
A2K2
i'm trying to get a cbo (drop-down value list) on a form to open
another form and go to a specific field if the choice selected is
"1", or go to the next field of the original form if the choice
selected is "0".
here's my code i put in the OnChange event:
IIF("FieldName"=1, (DoCmd.OpenForm "Form2", acNormal,,,acFormAdd,
acWindowNormal) (DoCmd.GoToControl "FieldName2"), 0)
it might just be the hangover, but i don't see what's missing.
thanks everyone

You can't sue the IIf function in that way. All of its arguments must
be values or expressions that return values, and can't be executable
statements. What you need to do is use a conventional If statement in
your event procedure. Also, I recommend you *not* use the Change event,
but rather use the combo box's AfterUpdate event. If the user picks an
item from the list using the mouse, there's not practical difference
between the events; however, if the user types a value in the control
instead, then the Change event will fire with every keystroke, while the
AfterUpdate event will fire only when the user's typing or selection is
complete.

Try code similar to this:

'----- start of example code -----
Private Sub YourComboName_AfterUpdate()

If Me!YourComboName = 1 Then
DoCmd.OpenForm "Form2", acNormal,,,acFormAdd
Forms!Form2!FieldName2.SetFocus
Else
' If you need code to achieve your other alternative,
' put it here. If not, you can delete the "Else" statement.
End If

End Sub
'----- end of example code -----
 

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

Back
Top