Data validation and setfocus

T

Terri

I am trying to perform some data validation on a subform. When my if
statement is triggered I get the msgbox, AccrualStartDate is set to null but
the focus does not go to AccrualStartDate. It goes to the next field in my
tab order. Any thoughts?


Private Sub AccrualStartDate_AfterUpdate()
If Not IsNull(AccrualEndDate) And DatePart("m", [AccrualEndDate]) <>
DatePart("m", [AccrualStartDate]) Then
MsgBox "The accrual start and end date must be in the same month."
Me.AccrualStartDate = Null
Me.AccrualStartDate.SetFocus
End If
End Sub
 
V

Van T. Dinh

AfterUpdate is too late since it the action(s) prior to the AfterUpdate
Event already decide where the Focus got to go to.

Use the BeforeUpdate Event to perform validation and if necessary, set
Cancel = True to cancel the Update Event and Events that lead to the Update
Event to retain the Focus on the TextBox.
 
Top