Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close the form with ESC buton?? 2

Status
Not open for further replies.

Fekri

Programmer
Joined
Jan 3, 2004
Messages
284
Location
IR
Hi all,

Is there any way to set the forms in access that can close the forms with using ESC key??

Thanks
Ali fekri
 
The easiest, I think, would be to create a button with close code, then just set it's Cancel property to Yes (other tab of properties). Code would look something like

[tt]docmd.close acform, me.name[/tt]

Else, I think you'd need to investigate the forms keydown/keypressed event (check KeyAscii/KeyCode against vbKeyEscape)

Roy-Vidar
 
Thanks Roy-vidar

So Great and beautifull

Ali
 
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!
 
Thanks a lot

That's so perfefct

Ali Fekri
 
Point to note out of interest..

For most access forms you can "back out" any changes you have made while on a record by pressing the ESC key. By redefining what the ESC key does in the manner above you will lose that functionality..

BuilderSpec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top