Validation

S

Shep99

For info:

The 2 fields I am trying to update are

1) Reported to vo (date)

And

2) Report Number

I have already entered the following :

Private Sub Reported_to_VO__date__AfterUpdate()
msgbox "Enter Report number"
Me.Report_Number.SetFocus
End Sub

This tells users to update 'Report Number' if they have updated 'Reported to
vo (date)'. This only tells them to update the field, but I want to make
sure they can't exit the form without inserting a 'report number' (only
providing they have inserted a date in the field 'reported to vo (date)')
..If they have not entered a date in the 'reported to VO (date) field then it
doesn’t matter about 'Report Number' field. Its only when they do enter a
date in 'reported to vo (date)' that I need that message to appear.

So, what message in what field do I need to insert in order for this to work?
 
D

Douglas J. Steele

Since you can't be sure of what order they're going to enter the values,
it's better to put logic in the form's BeforeUpdate event, rather than in
the textbox's AfterUpdate events.

What you need is something like:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Len(Me.Reported_to_VO_date) > 0 Then
If Len(Me.Report_Number & "") = 0 Then
MsgBox "Enter Report number"
Me.Report_Number.SetFocus
Cancel = True
End If
End If

End Sub
 
Top