Stay in box after error message

SueBK

Registered User.
Local time
Tomorrow, 08:34
Joined
Apr 2, 2009
Messages
197
I have an AfterUpdate code on a text box in a form that returns an error message when invalid data is entered and resets the field to a null value (thanks for your help).

However, it flicks the cursor to the next tab stop when the message box is closed and I would like the cursor to stay in the box. Is there a line of code that I can add that will do this?

My code is:
Code:
Private Sub Closed_AfterUpdate()
If Closed > Date + 7 Then
MsgBox "This is an actual closed date and therefore must occur in the past. You may not enter a future date."
Cancel = True
Me.Closed = Null
End If
End Sub
 
Where do I put that code? I tried a couple of places in the existing code, but nothing is working.
 
You could try something like;

Code:
If IsNull(Me.ControlName) then
     Me.ControlName.Setfocus
End If

In the Got Focus event of the next tab stop.
 
It doesn't matter where you put the SetFocus command, because after all the code in your AfterUpdate event has run, THEN the tab key pressed by the user will be processed. Also, Cancel has no meaning in the AfterUpdate event.

Use the code you posted with the BeforeUpdate event.
It should work then.

Evan
 

Users who are viewing this thread

Back
Top Bottom