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
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim ctr As Control
For Each ctr In Me.Controls
Select Case TypeName(ctr)
If KeyCode = 27 Then 'Esc key pressed