Fekri,
Spending Sunay afternoon catching up on this past weeks's posts, so I'm a little late. I use the Escape Key to exit a form because that's the way the application I'm replacing with Access exited its forms, and it's easier for some of the older users. You'll note that you can use the same code to assign custom actions to a variety of keys.
First, make your Form_Load sub like this:
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
That tells Access to check the keyboard for pressed keys.
Next, do this:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyEscape
DoCmd.Close acForm, "YourFormName", acSaveYes
Case vbKeyF2
' Process F2 key events.
Case vbKeyF3
' Process F3 key events.
Case vbKeyF4
' Process F4 key events.
Case Else
End Select
End Sub
Most special keys (FKeys, Up, Down, Left, Right Arrows etc) can be assigned in this manner.
Hope this helps.
There's ALWAYS more than one way to skin a cat!