Solved AfterUpdate() need to return to field on form...

Local time
Yesterday, 17:48
Joined
Sep 22, 2022
Messages
113
Hey all,

Still working on a ridership database and doing entry checking. I have DepartTime and ReturnTIme. The DepartTime must be > zero. When the user puts in Return time, I am checking to see if it is > DepartTime with the following AfterUpdate code entered. The check works but if they do put in an earlier time that the depart time, the focus changes to the next tab field. How can I set the cursor back to the ReturnTime field to be corrected?

I tried Me.ReturnTime.SetFocus but it returns an error about not the correct method.

Private Sub Return_AfterUpdate()

If Me.ReturnTime < Me.DepartTime Then
MsgBox "Return time can not be before Depart time. Please check your entries.
End If

End Sub

Thanks in advance...
 
Probably better to use the BeforeUpdate event instead.
 
I tried Me.ReturnTime.SetFocus but it returns an error about not the correct method.
As I could see your field is named as "Return" so use command :
Code:
Me.Return.SetFocus
 
As suggested, use Before Update event of the Control:

Private Sub ReturnTime_BeforeUpdate(Cancel As Integer)
Cancel = Nz(Me.ReturnTime, 0) < Me.DepartTime
If Then Cancel
MsgBox "Return time cannot be before Depart time. Please check your entries.
End If
End Sub
 
As suggested, use Before Update event of the Control:

Private Sub ReturnTime_BeforeUpdate(Cancel As Integer)
Cancel = Nz(Me.ReturnTime, 0) < Me.DepartTime
If Then Cancel
MsgBox "Return time cannot be before Depart time. Please check your entries.
End If
End Sub
That should more likely be ?
Code:
If Cancel Then
 
That did the trick. Steep learning curve for me. Didn't know what the Nz() function did, now I do.

:pThanks Folks...
 

Users who are viewing this thread

Back
Top Bottom