set focus

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Back
Top