'Serving the Microsoft® Access
Community since 1997'

Free Samples
About Us



Function Key Shortcuts

A default command button on an Access form works by being clicked with a mouse. I have worked with a number of clients over the years that do massive amounts of data entry using Access, and do not want to remove their hands from the keyboard. This tip shows how to allow keyboard Function Keys to emulate the click, thus leaving fingers on the keyboard.

NOTE: All the VBA code segments on the Database Lessons site assume that you have DAO references active. If you are not sure what this means, and you are using Microsoft Access 2000 or higher, click here.

  • on a form with a command button, change the form's "Key Preview" property to "Yes"
  • make sure the command button has a VBA "On Click" event
  • create an "On Key Down" event for the form
  • put code like this in the "On Key Down" event procedure
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

   If KeyCode = vbKeyF5 Then
      KeyCode = 0
   End If

End Sub

The above example allows the F5 function key to emulate the click of the cmdSomeButton command button. Make sure that you replace "cmdSomeButton" with the actual name of the command button.

This technique can also be used in situations without the command button.

Oh, by the way, if you want to know the proper "names" of other keys, besides function keys, go into the MS Access VBA help screen, and search for "Keycode Constants".

Happy Coding

(article continues after sponsor spot)

Note: This web site dedicated to MS Access database users is an independent publication of Richard W. Killey and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft® Corporation.


© 2006, 2007, 2008 Richard W. Killey. All Rights Reserved. - Privacy Policy