Solved

Urgent: HandleKeyUp

Posted on 2002-05-22
2
130 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:enric
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 7029024
private blnMsgBox as boolean

Private Sub Command1_Click()
blnMsgBox = true
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) and (blnMsgBox = false) Then 'Esc key pressed, but no messagebox
               Unload Me
           End If
   End Select
Next
blnMsgBox = False
End Sub

CHeers
0
 

Author Comment

by:enric
ID: 7029190
Angel, your answer gave me an idea on how to deal with my problem.  Thx!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Is an IP address in a Range 22 72
Window placement 17 65
vb6 connector to SQL Server 2 32
VB6 - Compare and highlight cell not the same 3 33
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now