set focus

G

Guest

I am trying to stop entry of a future date and clear the field and move the
cursor back to the same field. Everything works except the set focus. It
goes to the next field. I tried it in exit and lost focus events.

If txtDateInRepair > Date Then
MsgBox ("You Can't input a date Passed Todays Date")
txtDateInRepair = Null
Me.txtDateInRepair.SetFocus
 
E

Ed Robichaud

You can't a set control's focus to itself on the way out, but you can use
the OnEnter event of the next control in tab order to fire the error msgbox
() and move focus back to the previous control. You can also use the same
error checking on the form's BeforeUpdate event and/or its Close event.
-Ed
 
G

Guest

Why not just set the Validation of the field to:
<=Date()
This will require that a future date cannot be entered. It will also leave
the cursor in the field until the validation requirement is met.

Mr. B
 
K

Ken Snell [MVP]

Use the BeforeUpdate event of the control:

Private Sub txtDateInRepair_BeforeUpdate(Cancel As Integer)
If txtDateInRepair > Date Then
MsgBox ("You Can't input a date Passed Todays Date")
Cancel = True
End If
End Sub
 
G

Guest

Thank you one and all

Ken Snell said:
Use the BeforeUpdate event of the control:

Private Sub txtDateInRepair_BeforeUpdate(Cancel As Integer)
If txtDateInRepair > Date Then
MsgBox ("You Can't input a date Passed Todays Date")
Cancel = True
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top