Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Urgent: HandleKeyUp

Posted on 2002-05-22
2
Medium Priority
?
140 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 150 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

610 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