enric
asked on
Urgent: HandleKeyUp
I'm facing a problem when I press the 'ESC' key when the message box is shown, the form will be unload instead of unloading the messagebox. The 'ESC' key is used as the shortcut key for user to unload the form. I understand that messagebox with vbOkOnly as VbMsgBoxStyle will unload if any key was press by the user. Therefore, when the user press 'ESC' key, VB identify it as a key to unload the form as well as the messagebox.
Is there any better solution to control that if ESC key is pressed when there is a messagebox, the messagebox should be unload instead of the form. Pls help !
I've included a sample of my code for your better review. Pls take note that the form's property KeyPreview should set to True.
Private Sub Command1_Click()
MsgBox "Hello", vbOKOnly
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim ctr As Control
For Each ctr In Me.Controls
Select Case TypeName(ctr)
Case "CommandButton"
If KeyCode = 27 Then 'Esc key pressed
Unload Me
End If
End Select
Next
End Sub
Is there any better solution to control that if ESC key is pressed when there is a messagebox, the messagebox should be unload instead of the form. Pls help !
I've included a sample of my code for your better review. Pls take note that the form's property KeyPreview should set to True.
Private Sub Command1_Click()
MsgBox "Hello", vbOKOnly
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim ctr As Control
For Each ctr In Me.Controls
Select Case TypeName(ctr)
Case "CommandButton"
If KeyCode = 27 Then 'Esc key pressed
Unload Me
End If
End Select
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER