In my application vehicles arrive and depart from a workshop. The
ArrivalDate and the HandoverDate are each entered. Sometimes the
person who should enter the arrival date forgets to do so.
When the vehicle is handed over to the customer and the HandoverDate is
entered I wish to warn about the possibly missing ArrivalDate. In the
BeforeUpdate event of HandoverDate I have:
Private Sub HandoverDate_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.HandoverDate) And IsNull(Me.ArrivalDate) Then
MsgBox "Please enter the Arrival date and then re-enter the
Handover date", ,
"This vehicle appears not to have arrived"
Cancel = True
Me.HandoverDate.Undo
Me.ArrivalDate.SetFocus
End If
End Sub
Everything works fine except for the final SetFocus. This gives rise
the error:
Run-time error 2108: You must save the field before you execute the
SetFocus method.
That is clear enough but I am undoing the entry and cancelling the
update. I guess that the Cancel does not have an effect until the
event routine has exited.
Where do I sensibly put the SetFocus?
I could put it in the AfterUpdate event but I would then have to put
some boolean variable in the BeforeUpdate and test it in AfterUpdate.
Seems a bit too messy.