Run Time Errors after upgrading to newest version (1 Viewer)

jbroadnax

New member
Local time
Today, 03:58
Joined
Jan 16, 2018
Messages
1
We recently upgraded to the newest version of Microsoft Access...after doing so, We are receiving the run time error below. Below is the code generating the error......


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim CurRec As Long, RecCnt As Long

CurRec = Me.CurrentRecord
RecCnt = Me.Recordset.RecordCount

If RecCnt <> 0 Then
If Shift = 0 Then
If KeyCode = vbKeyDown Then
If Me.NewRecord = True Or CurRec = RecCnt Then
Me.Recordset.MoveFirst
KeyCode = 0
ElseIf CurRec < RecCnt Then
Me.Recordset.MoveNext
KeyCode = 0
End If
ElseIf KeyCode = vbKeyUp Then
If Me.NewRecord = True Or CurRec = 1 Then
Me.Recordset.MoveLast
KeyCode = 0
ElseIf CurRec > 1 Then
Me.Recordset.MovePrevious
KeyCode = 0
End If
End If
End If
End If
End Sub


This is preventing us from pushing ahead with the Office 365 migration....Any help would be greatly appreciated...
 

Attachments

  • accesserror.jpg
    accesserror.jpg
    9 KB · Views: 50

isladogs

MVP / VIP
Local time
Today, 08:58
Joined
Jan 14, 2017
Messages
18,219
First of all, welcome to AWF

Assume you mean to Access 2016 - 32 bit or 64 bit? From which version?

Each new version of Access is less forgiving of code issues than the previous version so its unusual but quite possible than things may fail due to an upgrade

However the code seems a very convoluted way of moving to the next, first or previous record depending on the situation. Am I understanding it correctly?
If so, there are easier ways of achieving the same thing
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:58
Joined
Feb 28, 2001
Messages
27,179
This is not the way that you normally move to a given record on a bound form. I don't know that you CAN do this - but then again, Access didn't let you, did it? So maybe (if my guess is correct) you can't do this.

Here's the way I would approach it. This is going to sound convoluted, but bear with me. Use a command button with wizards enabled and tell it you want to navigate the form to a given record. Then examine the code that it built for you. That code will involve a .RecordsetClone and a .Recordset.BookMark - which you can manipulate to force the form to move to another record.

You can probably do away with the command button and its code once you see what your current Access Form Wizard does for record navigation. But here's the point. If you want to do something, often you can use the Command Button wizards to tell you how your current version of Access wants it done. Because, you see, the button wizards are as unimaginative as a box of rusty garden tools - but they are always right. So get the wizard to create some code and then adapt it.

BTW - using the .RecordsetClone, you can test for EOF or BOF BEFORE you decide to move anything. So you can safeguard the operation to avoid moving to an impossible record.
 

Users who are viewing this thread

Top Bottom