IIF(...

  • Thread starter Thread starter Maracay
  • Start date Start date
M

Maracay

Hi guys,

I placed this Fuction =IIf([tfrom]>[tTo],"Time to must be higher that Time
from") in the validation rule for tTo, both are Time fields, but for some
reason is not working.

May someone give me a hand with this.

Thanks
 
Firstly, IIf takes three arguments, not two. It works like this:

IIf( <some condition>, <value if condition is true>, <value if condition is
not true>)

It is intended to return a conditional value, and is not appropriate for a
validation rule.

You could use the validation rule like this:
Validation rule: >=[tFrom]
Validation text: "Time to must be higher that Time from"

Personally I would not do this as it could be restrictive and annoying for
the user. For example, the user might have entered a [tTo] value earlier
than [tFrom], intending to then change the [tFrom] value to something
appropriate.

A better approach, when validating one field value relative to another, is
to use the Form_BeforeUpdate event procedure:

If [tFrom] > [tTo] Then
MsgBox "Time to must be higher that Time from"
[tTo].SetFocus
Cancel = True
Exit Sub
End If

If you are not saving a record, but are using values in unbound controls to,
say, filter a report, then the same code should go in the Click event
procedure of the command button that launches the action.
 
Back
Top