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

R

RichW

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

GB

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...
 
K

Klatuu

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
 
K

Krzysztof Naworyta

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 <[email protected]> napisa³

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

--
KN

archiwum grupy:
http://groups.google.pl/advanced_search
(grupa: pl*msaccess)
 

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

Top