Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"You can't go to the specified record." Error Code 2105

367 views
Skip to first unread message

RichW

unread,
Sep 28, 2009, 7:38:02 AM9/28/09
to
I have a form that uses buttons and code similar to the following for
navigating through records:

***********************
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,


GB

unread,
Sep 28, 2009, 8:01:01 AM9/28/09
to
Just something I ran across while trying to debug a program, if you are step
tracking the procedure, you may get an error when attempting to execute the
docmd.gotorecord. If not already doing so, should try to execute the command
without "watching" the program go line by line. You could also msgbox the
err.number that would confirm what error number you are actually getting. As
for whether there *is* a next record you could track other data to present
the information you are looking for. Like look at the recordset that is in
memory, etc...

Klatuu

unread,
Sep 28, 2009, 10:05:04 AM9/28/09
to
You need to determine where you are in the recordset and enable or disable
the buttons so the next button will be disabled when the last record in the
form's recorset is reached. You also need to do the same for the first
record when moving backwards in the recordset. Here is an example of how you
can do this:

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

Krzysztof Naworyta

unread,
Sep 28, 2009, 11:13:14 AM9/28/09
to
This kind of errors is just VBA error, and never triggers Form_Error
event.
Form_Error is triggered by conflicts with validation rules, data types,
indexes, relations et cetera, et cetera...

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)

0 new messages