Data validation and setfocus

  • Thread starter Thread starter Terri
  • Start date Start date
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
 
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.
 

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

Similar Threads

Problems after enter press. 3
Access Form Validation 2
if statement 5
Force Validation prior to leaving form. 3
no current record 1
Month problem 2
Retrieving one months data 1
If code works initially 1

Back
Top