dbTalk Databases Forums  

KeyPress triggering Click event

comp.databases.ms-access comp.databases.ms-access


Discuss KeyPress triggering Click event in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bob Darlington
 
Posts: n/a

Default KeyPress triggering Click event - 12-30-2011 , 12:37 AM






I'm using Access 2010 with a form containing a list box.
The code I'm using for the KeyPress event in the list box, calls the
after update event for the same control. But somehow, it is also
triggering a call to the Click Event.
It's happening on one form, but not on another with a similar set up.
Can anyone point me in the right direction?
--
Bob Darlington
Brisbane

Reply With Quote
  #2  
Old   
Stuart McCall
 
Posts: n/a

Default Re: KeyPress triggering Click event - 12-30-2011 , 05:36 AM






"Bob Darlington" <bob (AT) dpcman (DOT) com.au> wrote

Quote:
I'm using Access 2010 with a form containing a list box.
The code I'm using for the KeyPress event in the list box, calls the after
update event for the same control. But somehow, it is also triggering a
call to the Click Event.
It's happening on one form, but not on another with a similar set up.
Can anyone point me in the right direction?
--
Bob Darlington
Brisbane
The up & down arrow keys trigger a click event in listboxes. Could these be
the keys you're trying to control? If so, consider using the KeyDown event
to detect them, then destroy the keypress using KeyCode = 0. I'm pretty sure
that'll occur before they are passed to the listbox.

Select Case KeyCode
Case vbKeyDown
KeyCode = 0
'process the key here
Case KeyUP
KeyCode = 0

....

Reply With Quote
  #3  
Old   
Bob Darlington
 
Posts: n/a

Default Re: KeyPress triggering Click event - 12-30-2011 , 05:41 PM



On 30/12/2011 9:36 PM, Stuart McCall wrote:
Quote:
"Bob Darlington"<bob (AT) dpcman (DOT) com.au> wrote in message
news:4efd5c2a$0$26205$c3e8da3$c14f6927 (AT) news (DOT) astraweb.com...
I'm using Access 2010 with a form containing a list box.
The code I'm using for the KeyPress event in the list box, calls the after
update event for the same control. But somehow, it is also triggering a
call to the Click Event.
It's happening on one form, but not on another with a similar set up.
Can anyone point me in the right direction?
--
Bob Darlington
Brisbane

The up& down arrow keys trigger a click event in listboxes. Could these be
the keys you're trying to control? If so, consider using the KeyDown event
to detect them, then destroy the keypress using KeyCode = 0. I'm pretty sure
that'll occur before they are passed to the listbox.

Select Case KeyCode
Case vbKeyDown
KeyCode = 0
'process the key here
Case KeyUP
KeyCode = 0

...


Thanks Stuart.
THe KeyPress event reads the KeyCode (Character) and tries to match a
record starting with that character in the ListBox. It finds the first
record OK every time (for any character), and sets a module level
variable to record its index and calls the ListBox AfterUpdate event
(which applies the form filter etc).
But when the same key is pressed again (looking for a second instance
with the same first character) the ListBox flashes to the correct
record, and then reverts to the previous record.

Further testing using message boxes shows that:
1. The KeyPress event occurs once
2. The AfterUpdate event occurs 3 times (called once each by the
KeyPress and Click events and once from somewhere I can't detect).
3. The Click event occurs once.

The KeyDown event is used disabled at present.
If I break the code and step through after the KeyPress message box
(right at the beginning of the event sub), the AfterUpdate event only
gets called once, the Click event doesn't get called and all works as
intended.

I'm obviously missing something to do with ListBox behaviour, but what?



--
Bob Darlington
Brisbane

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.