SetFocus in DataSheet View

crhodus

Registered User.
Local time
Today, 10:54
Joined
Mar 16, 2001
Messages
257
I have a subForm with a default view of DataSheet. In this subform, I have a field named txtCourse_Date. If the user enters a year that is less than the current year minus two (YEAR(NOW()) - 2), then I want to tell the user to correct the data.

The problem that I'm having is that if they click on another row of data in the datasheet, the message does not execute. The same thing seems to occur if the user clicks on a button located on the main form that the subform is attached to.

Here is the code that I'm currently using. Should I take another approach when trying to keep the cursor in the txtCourse_Date cell?

Here is what I'm currently doing:

Code:
Private Sub txtCourse_Date_Exit(Cancel As Integer)
    If Not IsNull(txtCourse_Date.Value) Then
        If (Year(txtCourse_Date.Value)) < ((Year(Now())) - 2) Then
            MsgBox ("The year that you entered into the Course Date falls outside the 2 year CE window. Please correct the year or delete this record.")
            ''// Keep focus in the txtCourse_date field. //
            Cancel = True
            Exit Sub
        End If
    End If
End Sub

Thanks,
Crhodus
 
After further debugging, I realized that my code was not being executed in the order that I expected it to. I had other code in the BeforeUpdate event that was being executed before the Exit event which prevented the above posted code from being executed.

Thanks,
CRhodus
 

Users who are viewing this thread

Back
Top Bottom