C
croy
I have a textbox control (txtSurveyDate) for a date field,
and I've put some code for that control on the BeforeUpdate
event to alert the user if they put in last year's date.
If they *have* put in last year's date, my message box will
alert them, and give them the choice of accepting that date
or cancelling.
The problem is, when the user selects "Cancel", my code
"un-does" and cancels the entire record, and leaves the
focus at the said control (which is not the first control
for the record).
What I would prefer, is when the user selects "Cancel", that
the focus would stay on that control, without further error
messages.
Here's the code:
******
Private Sub txtSurveyDate_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_txtSurveyDate_BeforeUpdate
If Me.NewRecord Then
If Year([txtSurveyDate]) = Year(Now()) - 1 Then
DoCmd.Beep
Dim Msg, Style, Title, Response
Msg = "If you sure the year you entered is_
correct, click 'OK'. " & vbCrLf &_
"Otherwise, click 'Cancel'"
Style = 1 + 32 + 256
Title = "The year you entered may not be_
correct"
Response = MsgBox(Msg, Style, Title, _
Help, Ctxt)
If Response = 2 Then
Me.Undo
Cancel = True
End If
End If
End If
Exit_txtSurveyDate_BeforeUpdate:
Exit Sub
Err_txtSurveyDate_BeforeUpdate:
MsgBox Err.Description
Resume Exit_txtSurveyDate_BeforeUpdate
End Sub
******
and I've put some code for that control on the BeforeUpdate
event to alert the user if they put in last year's date.
If they *have* put in last year's date, my message box will
alert them, and give them the choice of accepting that date
or cancelling.
The problem is, when the user selects "Cancel", my code
"un-does" and cancels the entire record, and leaves the
focus at the said control (which is not the first control
for the record).
What I would prefer, is when the user selects "Cancel", that
the focus would stay on that control, without further error
messages.
Here's the code:
******
Private Sub txtSurveyDate_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_txtSurveyDate_BeforeUpdate
If Me.NewRecord Then
If Year([txtSurveyDate]) = Year(Now()) - 1 Then
DoCmd.Beep
Dim Msg, Style, Title, Response
Msg = "If you sure the year you entered is_
correct, click 'OK'. " & vbCrLf &_
"Otherwise, click 'Cancel'"
Style = 1 + 32 + 256
Title = "The year you entered may not be_
correct"
Response = MsgBox(Msg, Style, Title, _
Help, Ctxt)
If Response = 2 Then
Me.Undo
Cancel = True
End If
End If
End If
Exit_txtSurveyDate_BeforeUpdate:
Exit Sub
Err_txtSurveyDate_BeforeUpdate:
MsgBox Err.Description
Resume Exit_txtSurveyDate_BeforeUpdate
End Sub
******