Microsoft Access
--
Questions
--
Followers
Top Experts
Any ideas?
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Try using the KeyUp event instead.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
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(KeyAsc
  If KeyAscii = 27 Then
    MsgBox "You pressed the ESC key"
  End If
End Sub
JeffCoachman
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.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
For some reason - unlike the Form_KeyDown handler - it will not capture a press on the Escape key.
no solution
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
You would need to set the form's KeyPreview property to true for this to work.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Which may be the problem to start with ?
mx
 Sometimes the answer is "you really can't to that", which in of itself, is an answer.
Jim.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
?
Jim.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
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.
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
 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.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Microsoft Access
--
Questions
--
Followers
Top Experts
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.


