Error 2105

E

Edward

Hello, Everyone.

I'm pretty well-versed with Access, but this is driving me nuts. I figure
it's a simple solution, but my brain just isn't wrapping around it right
now.

I'm using Access 2000, and I'm trying to trap for an error # 2105 (can't go
to specified record) if someone clicks on a navigation button and is already
at the beginning or end of the recordset--respectively. I want to move to
the last record if they are at the first record and click "PREVIOUS" and do
the reverse if they are at the last record. Any suggestions?

TIA!

Edward
 
T

tina

well, presumably you have two command buttons: one for Next and one for
Previous.

if the user is on the first record and clicks Next, of course you want to
move to the next record, and it should do so without an error occurring, so
no problem there. if the user clicks Previous, then the error should occur.
so add code to the Previous button, in the error handler, to move to the
Last record when the error occurs. example:

Select Case 2105
DoCmd.RunCommand acCmdRecordsGoToLast

if the user is on the last record and clicks Previous, of course you want to
move to the previous record, and it should do so without an error occurring,
so no problem there. if the user clicks Next, then the error should occur.
so add code to the Next button, in the error handler, to move to the First
record when the error occurs. example:

Select Case 2105
DoCmd.RunCommand acCmdRecordsGoToFirst

hth
 
E

Edward

Tina,

Thanks for writing. I meant to write earlier that I had already done this
in the error handler on the form and for each of the command buttons (yes, I
do have both). For some reason, it still isn't trapping the error. This is
what has been driving me batty. Any other suggestions? LOL

Thanks,

Edward
 
D

Dale Fye

Edward,

Usually, when I create custom navigation buttons, I disable the First and
Previous buttons when I am on the first record, and disable the Next and
Last buttons when I am on the last record. I do this by creating a Buttons
subroutine and calling it in the forms Current event. The code for the
Buttons routine might look like:

Public Sub Buttons

Dim rs as DAO.Recordset
Set rs = me.recordsetclone

me.first.enabled = me.CurrentRecord > 1
me.previous.enabled = me.CurrentRecord > 1

me.next.enabled = me.currentRecord < rs.RecordCount
me.last.enabled = me.currentRecord < rs.RecordCount

rs.close
set rs = nothing
end sub

However, if you are intent on looping through the records, you could avoid
the error altogether by modifying the code in the Click of the Previous
button to look like the following.

Private Sub cmd_Previous()

If me.currentRecord > 1 then
docmd.gotorecord ,,acPrevious
Else
docmd.gotorecord ,,acLast
end if

End Sub

Private Sub cmd_Next_Click()

'This requires a reference to DAO
Dim rs as dao.recordset
set rs = me.recordsetclone

if me.currentRecord = rs.RecordCount then
docmd.gotorecord ,,acFirst
else
docmd.gotorecord ,,acNext
end if

rs.close
set rs = nothing

End Sub

HTH
Dale
 
E

Edward

Thanks, Dale. That worked

Edward


Dale Fye said:
Edward,

Usually, when I create custom navigation buttons, I disable the First and
Previous buttons when I am on the first record, and disable the Next and
Last buttons when I am on the last record. I do this by creating a
Buttons subroutine and calling it in the forms Current event. The code
for the Buttons routine might look like:

Public Sub Buttons

Dim rs as DAO.Recordset
Set rs = me.recordsetclone

me.first.enabled = me.CurrentRecord > 1
me.previous.enabled = me.CurrentRecord > 1

me.next.enabled = me.currentRecord < rs.RecordCount
me.last.enabled = me.currentRecord < rs.RecordCount

rs.close
set rs = nothing
end sub

However, if you are intent on looping through the records, you could avoid
the error altogether by modifying the code in the Click of the Previous
button to look like the following.

Private Sub cmd_Previous()

If me.currentRecord > 1 then
docmd.gotorecord ,,acPrevious
Else
docmd.gotorecord ,,acLast
end if

End Sub

Private Sub cmd_Next_Click()

'This requires a reference to DAO
Dim rs as dao.recordset
set rs = me.recordsetclone

if me.currentRecord = rs.RecordCount then
docmd.gotorecord ,,acFirst
else
docmd.gotorecord ,,acNext
end if

rs.close
set rs = nothing

End Sub

HTH
Dale
 

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