Run time Error '2046'

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I'm still new to Access, so I don't fully understand it. So I am taking an online class on Access and in the instructor's video, he has the following code:

VBA Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   'MsgBox ("The keycode is " & KeyCode)
   'Displays the keycode for the key pressed in a messagebox
   Select Case KeyCode
      Case vbKeyEnd
         'Turns off the keys
         KeyCode = 0
         'Moves cursor to last line of the record
         DoCmd.RunCommand acCmdRecordsGoToLast
      Case vbKeyHome
         'Turns off the keys
         KeyCode = 0
         'Moves cursor to first line of the record
         DoCmd.RunCommand acCmdRecordsGoToFirst
      Case vbKeyUp
         'Turns off the keys
         KeyCode = 0
         'Moves cursor to previous line of the record
         DoCmd.RunCommand acCmdRecordsGoToPrevious
      Case vbKeyDown
         'Turns off the keys
         KeyCode = 0
         'Moves cursor to next line of the record
         DoCmd.RunCommand acCmdRecordsGoToNext
   End Select
However, when I run this code, I get the following error:
Run-time error '': The command or action 'RecordsGoToNext' isn't available now.
What does that me as far as Access is concerned. I'm not sure if the version of access matters with this code. Any help would be greatly appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,
I have never used a Form_KeyDown Event so I am not to sure about this issue...
Do you have any records in that form?

I guess you don't have a record to GoToNext...and that is why you are getting this error well at least thats what I think it might is the problem.

HTH
 
Upvote 0
I have to wonder if you were given that and expected to raise this issue and solve it yourself? If not, it's a surprising oversight - that you cannot go to next if at the end, nor go to previous if at the beginning. You have 2 choices for "fixing" - trap the error or test the cursor position (i.e. where are you in the recordset?) and either do nothing or message "You are already at the end/beginning of the records". Or just don't try to navigate beyond the first or last. In other words, don't try to advance when you're at the end and vice versa.
 
Upvote 0

Forum statistics

Threads
1,225,149
Messages
6,183,184
Members
453,151
Latest member
Lizamaison

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