Thank you John. Yes, I agree that VBA code is more powerful. Unfortunately
I don't know it! I have [several] questions where the 1st question asks for
a number and the following question asks for another number that must be <=
to the previous number entered. Since you can't use the value of another
control in a validation rule for a control, I'm have trouble visualizing the
easiest way to accomplish this. Is VBA code in the form's BeforeUpdate event
the only way to do this? Can this be done in a macro? And your correct, I
do indeed need different error messages for each error.
If that were the only rule (I gather that it isn't) then a table validation
rule might be
[FirstField] IS NOT NULL AND [SecondField] IS NOT NULL
And [SecondField] <= [FirstField]
with a validation text like
"Both Firstfield and secondfield must be entered, and secondfield must be less
than or equal to firstfield".
As you can see, this can get hairy with multiple rules!
I'm not experienced with macros; VBA for this kind of thing is actually easier
since you can use If... Then blocks of code.
Since I don't know the structure of your table or your rules, I can't be
specific about the code; but it would be something like
Private Sub Form_BeforeUpdate(Cancel as Integer)
If IsNull(Me!txtFirst) Then
MsgBox "First must be filled in!", vbOKOnly
Me!txtFirst.SetFocus
Exit Sub
End If
If IsNull(Me!txtSecond) Then
MsgBox "First must be filled in!", vbOKOnly
Me!txtSecond.SetFocus
Exit Sub
End If
If Me!txtSecond > Me!txtFirst Then
MsgBox "Second must be less than or equal to First", vbOKOnly
Me!txtSecond.SetFocus
Exit Sub
End If
.... <etc etc>
End sub