?
Solved

Urgent: HandleKeyUp

Posted on 2002-05-22
2
Medium Priority
?
138 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

777 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