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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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