Hello,
I have a form that displays records from a query. I've utilized the following code to allow users to navigate forward and back in records by using the left and right arrow keys on their keyboard:
The code works just fine when used upon opening the form. However, one of the fields that users edit for records is actually on a subform. When the user edits this field then tries to navigate with the arrow keys, the code doesn't work (because the focus is no longer on the main form). How do I force the focus back to the main form and/or how do I get the same code to work in the subform (I.e., when key is pressed in the subform, navigate forward or back in the recordset from the main form)?
I have a form that displays records from a query. I've utilized the following code to allow users to navigate forward and back in records by using the left and right arrow keys on their keyboard:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHandler
Select Case KeyCode
Case vbKeyLeft
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToPrevious
Case vbKeyRight
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToNext
End Select
Exit Sub
ErrHandler:
Select Case Err.Number
Case 2046
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
Resume Next
End Sub
The code works just fine when used upon opening the form. However, one of the fields that users edit for records is actually on a subform. When the user edits this field then tries to navigate with the arrow keys, the code doesn't work (because the focus is no longer on the main form). How do I force the focus back to the main form and/or how do I get the same code to work in the subform (I.e., when key is pressed in the subform, navigate forward or back in the recordset from the main form)?