I have a form with a frame. i want to close form with Esc Key and i m doing this. But when frame is visible then it should hide frame but its closing form. Is there any way to hide frame when frame is visible with Esc Key and close form when frame is hidden.
i am using this.
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
If frm1.Visible = True Then
frm1.Visible = False
Make sure keypreview is turned on otherwise (depending on what has focus) the event may not fire when the ESC key is pressed. Keypreview will allow the event to fire regaurdless if a text box may have the focus or some other control on the form.