Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHandler
'Private is it only works here.
'KeyCode and Shift are buckets to hold values
Dim ctl As Control
Dim fldName As String
Dim rst As DAO.Recordset
'MsgBox (" The keycode is " & KeyCode)
Select Case KeyCode
Case vbKeyEnd
KeyCode = 0 'turns off the key stroke, so when you press it, it won't move.
DoCmd.RunCommand acCmdRecordsGoToLast
Case vbKeyHome
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToFirst
Case vbKeyUp
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToPrevious
Case vbKeyDown
KeyCode = 0
DoCmd.RunCommand acCmdRecordsGoToNext
Case vbKeyRight, vbKeyLeft
Case 48 To 57, 65 To 90 '48-57 number keys, 65-90 upper/lower letters
Set ctl = Screen.ActiveControl
fldName = clt.Name
' [LastName] Like 'SMI*'
SrchVal = SrchVal & Chr(KeyCode)
KeyCode = 0
SrchCrit = "[" & fldName & "] Like '" & SrchVal & "*'"
Set rst = Me.RecordsetClone 'this is a duplicate of the control source of the form.
rst.findfirst SrchCrit
If rst.NoMatch Then
MsgBox (" Record not found! ")
Else
Me.Bookmark = rst.Bookmark
End If
rst.Close
Case 27 'esc key
SrchVal = ""
KeyCode = 0
Case 122 'F11
'Shift = 1, Ctrl = 2, Alt = 4
If Shift <> 4 Then
KeyCode = 0
End If
Case Else
KeyCode = 0
End Select
Exit Sub
ErrHandler:
Select Case Err.Number
Case 2046
Case Else 'This means if there is any other kind of error it will show what it is.
MsgBox (" Error " & Err.Number & " " & Err.Description & "! ")
End Select
Resume Next
End Sub