Andrew Fergus
MrExcel MVP
- Joined
- Sep 9, 2004
- Messages
- 5,462
- Office Version
- 365
- 2021
- 2016
- Platform
- Windows
I have an unbound form (it's like a 'help -> about' form) that I would like the user to be able to press the 'Esc' key to close the form rather than clicking a button. I have had a look through this forum, the MS site and Access help and I'm stuck - I'm trying to learn VB so please bear with me.
From what I gather I can set the 'key preview' event to 'yes' and then use the 'on key press' event to test for an ASCII character (I think it is ASCII number 27 for the 'Esc' key) and then close the form. So how do I code this in VB? Also, if I wanted to include other keys on the same function, such as the space bar and carriage return, how would these extra characters be added to the code? I'm using Access 2000.
Thanks in Advance
Andrew
Late Post : I realise I can do this with any key by using the following code, but would prefer to work off keys such as the 'Esc' key for when I get to other forms :
From what I gather I can set the 'key preview' event to 'yes' and then use the 'on key press' event to test for an ASCII character (I think it is ASCII number 27 for the 'Esc' key) and then close the form. So how do I code this in VB? Also, if I wanted to include other keys on the same function, such as the space bar and carriage return, how would these extra characters be added to the code? I'm using Access 2000.
Thanks in Advance
Andrew
Late Post : I realise I can do this with any key by using the following code, but would prefer to work off keys such as the 'Esc' key for when I get to other forms :
How would I add things like the 'Esc' and 'Space Bar' keys to this?Private Sub Form_KeyPress(KeyAscii As Integer)
DoCmd.Close
End Sub