Solved

Urgent: HandleKeyUp

Posted on 2002-05-22
2
136 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 448
Crystal reports - Formula Field code need assistance with code 17 100
MsgBox 4 75
VB script to continue despite error 2 77
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

737 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