***********************
Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
Exit_Next_Record_Click:
Exit Sub
Err_Next_Record_Click:
MsgBox Err.Description
Resume Exit_Next_Record_Click
End Sub
***********************
In this example, when the Next Record does not exist, I receive the
following message box:
"You can't go to the specified record."
I use the Immediate Window in an attempt to capture the Error Code
associated with the message box, but the Immediate Window remains blank. I
assume that this message is Error Code 2105.
I then enter the following code into the Forms "On Error" event so as to
customize the message box wording:
***********************
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const conErrRequiredData = 2105
If DataErr = conErrRequiredData Then
MsgBox ("The record does not exist")
Response = acDataErrContinue
Else
'Display a standard error message
Response = acdatadisplay
End If
End Sub
***********************
But the message box wording does not change.
Why do these error handling procedures fail to produce the expected results?
Appreciate the group's support and guidance.
Regards,
Sub SetNavButtons(ByRef frmSomeForm As Form)
On Error GoTo SetNavButtons_Error
With frmSomeForm
If .CurrentRecord = 1 Then
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
.cmdNextRec.SetFocus
.cmdFirstRec.Enabled = False
.cmdPreviousRec.Enabled = False
ElseIf .CurrentRecord = .Recordset.RecordCount Then
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdPreviousRec.SetFocus
.cmdNextRec.Enabled = False
.cmdLastRec.Enabled = False
Else
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
End If
End With
SetNavButtons_Exit:
On Error Resume Next
Exit Sub
SetNavButtons_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure SetNavButtons of Module modFormOperations"
GoTo SetNavButtons_Exit
End Sub
--
Dave Hargis, Microsoft Access MVP
You can just replace standard message (or simple "beep") in the same
procedure, using Select statement:
Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
Exit_Next_Record_Click:
Exit Sub
Err_Next_Record_Click:
select case err.number
case 2105
'Msgbox "The record does not exist"
Beep
case else
MsgBox Err.Description
end select
Resume Exit_Next_Record_Click
End Sub
--
KN
Juzer RichW <Ri...@discussions.microsoft.com> napisaďż˝
--
KN
archiwum grupy:
http://groups.google.pl/advanced_search
(grupa: pl*msaccess)