Run Time Error 2105 You can't go to specific record

psamu

Active Member
Joined
Jan 3, 2007
Messages
462
I have below code in the form properies event, I am getting run time error 2105 when I go to last record on both side (Above or below) How can I get rid of this error? Is there any way I can put this code entire form instead of each field properties? Thanks.


Private Sub Remarks_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode

Case 40
DoCmd.GoToRecord , , acNext
Case 38
DoCmd.GoToRecord , , acPrevious
End Select
End Sub
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
This would stop the error (and stop the record from moving any further if it reaches the first or last record) - the obvious point is that you can't move "past" the last record etc. With a few tweaks you could create a "circling" effect where the last records circles back to the first:

Code:
Private Sub Remarks_KeyDown(KeyCode As Integer, Shift As Integer)

[COLOR="Blue"]On Error Resume Next[/COLOR]
Select Case KeyCode
    Case 40
        DoCmd.GoToRecord , , acNext
    Case 38
        DoCmd.GoToRecord , , acPrevious
End Select

End Sub

I'm not sure about trapping key events on a form level, though. Perhaps you should say more about what you want to happen and how this is supposed to work - where this code is being used, and so on and so forth.
 
Upvote 0

Forum statistics

Threads
1,215,340
Messages
6,124,382
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top