Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 800
  • Last Modified:

Form_KeyDown event in Access not firing when press Escape key

For some reason it fires when I press CTRL, but not ESC.

Any ideas?
0
TimHudspith
Asked:
TimHudspith
  • 6
  • 4
  • 4
  • +2
2 Solutions
 
IrogSintaCommented:
According to this link, the KeyDown event does not occur when you press the ESC key if the form has a command button for which the Cancel property is set to Yes.

Try using the KeyUp event instead.
0
 
TimHudspithAuthor Commented:
My question needs amending: this behaviour relates to the ListView_KeyDown event.
0
 
IrogSintaCommented:
I don't understand. Is it not the Escape key anymore we're talking about?
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Jeffrey CoachmanMIS LiasonCommented:
TimHudspith,

What is your ultimate goal here...?

If you want to see if the ESC key was pressed for a control, then you may have to use the KeyPRESS event not the KeyDown event

Private Sub YouListBox_KeyPress(KeyAscii As Integer)
    If KeyAscii = 27 Then
        MsgBox "You pressed the ESC key"
    End If
End Sub


JeffCoachman
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"ListView_KeyDown event"

Are you talking about the Microsoft ActiveX List View control - if so, there is no Keydown event.

1
2
0
 
Jeffrey CoachmanMIS LiasonCommented:
TimHudspith,

MX is correct, ..
I saw "ListView", and thought "ListBox".
:-(

What does a ListView do for you that a Listbox cannot?

Still not clear on your ultimate goal here.
0
 
TimHudspithAuthor Commented:
Sorry for the late response to this, but the list view (MS common control Lib.) does have a Keydown event, but it does not show in the event list in the properties window. It is only accessible through the form code module.

For some reason - unlike the Form_KeyDown handler - it will not capture a press on the Escape key.
0
 
TimHudspithAuthor Commented:
I've requested that this question be deleted for the following reason:

no solution
0
 
IrogSintaCommented:
I assume your trying to deselect an item you just selected in the listview control.  How about using the Form's KeyDown event along with ActiveControl like this:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 27 And Me.ActiveControl.Name = "ListView1" Then
        Me.ListView1.SelectedItem.Selected = False
    End If
End Sub

Open in new window

You would need to set the form's KeyPreview property to true for this to work.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"You would need to set the form's KeyPreview property to true for this to work."
Which may be the problem to start with ?

mx
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
Tim,

<<Sorry for the late response to this, but the list view (MS common control Lib.) >>

  Your going to find that there are few controls that work properly and fully with Access as it does not have a full implementation of the COM interfaces.

  Unless a control is stated as specifically working with Access, it's best to stay away from it.

  The behavior your seeing is a result of that.  Access/VBA is the not the same as VB.

Jim.
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
I should also add with that the fact that there is no solution is not  the fault of those answering the question in all cases.

  Sometimes the answer is "you really can't to that", which in of itself, is an answer.

Jim.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
OK ... I just added a ListView Ax Control to a Form.
I went into the code behind the LV ... and added a Msgbox in the KeyDown event.

It works for me - see images.

Be *sure* the Form's Key Preview is set to Yes.

KeyDown ...

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
OK ... the only key event that seems to work - for ESCAPE - for the ListView control is KeyUp ... see image.

ESC - Key UP
0
 
TimHudspithAuthor Commented:
Thanks for responses. Jim Dettman - as you say, it is one of those things that just cannot be done.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Well ... apparently not with Key Down, but it can with Key Up ...

?
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
As MX has pointed out, it seems you can get what you want with Keyup.  Please check out his comments and if that's the case, I'll re-open the question so you can reassign points.

Jim.
0
 
IrogSintaCommented:
Be *sure* the Form's Key Preview is set to Yes.
No need to do this.
You only need to set the form's KeyPreview property to Yes if you are using the Form's KeyUp, KeyDown, or KeyPress event just like in the example I gave earlier.

The KeyUp event of the ListView control works (as pointed out by MX).  No need to change the KeyPreview property.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"You only need to set the form's KeyPreview property to Yes if you are using the Form's KeyUp, KeyDown, or KeyPress event just like in the example I gave earlier."

The things one forgets. Thx for the reminder ... :-)

Jim ... no worries about reopening.  I was really just curious as to why this was not working at all.  And still, bit of odd behavior.



mx
0
 
Jim Dettman (Microsoft MVP/ EE MVE)PresidentCommented:
<<Jim ... no worries about reopening. >>

 For future readers, it's always best to make sure things are as they should be.  If the technique solves the problem, it should be labled as such.

Jim.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now