Event Procedure

S

Shep99

On my form I have a field which 'if' updated, another field must be updated
before leaving the record.

For info (Report to Vo Date is the field that may get updated and Report
Number is the field that must be updated if the report to VO date is entered)

The event i have at the moment:

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

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


The 'enter report number' error appears even before you have chance to enter
the number..........Can I change the time the message appears to when you try
and exit the record rather then straight away ?
 
O

Ofer

You get the message after you update the field Reported_to_VO__date, if you
don't want to happen drop the msgbox line

Private Sub Reported_to_VO__date__AfterUpdate()
' Drop this line
' msgbox "Enter Report number"
Me.Report_Number.SetFocus
End Sub
 
S

Shep99

i do want to get the message but only if the user trys to exit the record
without updating report number?
 
O

Ofer

This is why you get it on the before update event of the form, but you don't
need it on the after update event of the field

'********************************************
' the before update of the form, you need it here
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Len(Me.Reported_to_VO__date_) > 0 Then
If Len(Me.Report_Number & "") = 0 Then
' You need that
msgbox "Enter Report number"
Me.Report_Number.SetFocus
Cancel = True
End If
End If

End Sub
'********************************************
' After update of the field, where you don't want it
Private Sub Reported_to_VO__date__AfterUpdate()
' Remove this line
' msgbox "Enter Report number"
Me.Report_Number.SetFocus
End Sub
 
Top