dbTalk Databases Forums  

List Box KeyDown Behaviour

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


Discuss List Box KeyDown Behaviour in the comp.databases.ms-access forum.



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

Default List Box KeyDown Behaviour - 07-20-2011 , 06:50 PM






I'm using an unbound multi select list box in an Access 2010 accdb.
I want to apply a filter to the form so that it displays data for the
currently selected row in the list box when I move from row to row in the
list box using the down arrow key.
(Note: I can do the same thing without a problem using the After Update
event for the list box when a row is selected using the mouse, but I also
want to provide the ability to use the keyboard only.)

But when the arrow down keyboard key is used, the after update event doesn't
trigger until after the focus moves to the next row, so that the form
displays the data for the previously selected row.

I've tried using the following in the KeyDown event for the list box:
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
MsgBox Me!lstLAN
End If
Before the event triggers, the list box has a non null value, and the arrow
down does move to the next row. But the code generates a null value even
though the focus has moved to the next row.

I really don't understand why the afterupdate behaviour should be different
for mouse clicking vs arrow down, but I would like to be enlightened.
Does anyone have an alternative solution for what I'm trying to achieve.

Bob Darlington
Brisbane

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

Default Re: List Box KeyDown Behaviour - 07-20-2011 , 11:41 PM






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

Quote:
I'm using an unbound multi select list box in an Access 2010 accdb.
I want to apply a filter to the form so that it displays data for the
currently selected row in the list box when I move from row to row in the
list box using the down arrow key.
(Note: I can do the same thing without a problem using the After Update
event for the list box when a row is selected using the mouse, but I also
want to provide the ability to use the keyboard only.)

But when the arrow down keyboard key is used, the after update event
doesn't trigger until after the focus moves to the next row, so that the
form displays the data for the previously selected row.

I've tried using the following in the KeyDown event for the list box:
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
MsgBox Me!lstLAN
End If
Before the event triggers, the list box has a non null value, and the
arrow down does move to the next row. But the code generates a null value
even though the focus has moved to the next row.

I really don't understand why the afterupdate behaviour should be
different for mouse clicking vs arrow down, but I would like to be
enlightened.
Does anyone have an alternative solution for what I'm trying to achieve.

Bob Darlington
Brisbane
A listbox's click event fires for each up or down navigation, so use that
instead of afterupdate. HTH

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

Default Re: List Box KeyDown Behaviour - 07-21-2011 , 02:24 AM



"Stuart McCall" <smccall (AT) myunrealbox (DOT) com> wrote

Quote:
"Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote in message
news:4e2769c5$0$22474$afc38c87 (AT) news (DOT) optusnet.com.au...
I'm using an unbound multi select list box in an Access 2010 accdb.
I want to apply a filter to the form so that it displays data for the
currently selected row in the list box when I move from row to row in the
list box using the down arrow key.
(Note: I can do the same thing without a problem using the After Update
event for the list box when a row is selected using the mouse, but I also
want to provide the ability to use the keyboard only.)

But when the arrow down keyboard key is used, the after update event
doesn't trigger until after the focus moves to the next row, so that the
form displays the data for the previously selected row.

I've tried using the following in the KeyDown event for the list box:
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
MsgBox Me!lstLAN
End If
Before the event triggers, the list box has a non null value, and the
arrow down does move to the next row. But the code generates a null value
even though the focus has moved to the next row.

I really don't understand why the afterupdate behaviour should be
different for mouse clicking vs arrow down, but I would like to be
enlightened.
Does anyone have an alternative solution for what I'm trying to achieve.

Bob Darlington
Brisbane

A listbox's click event fires for each up or down navigation, so use that
instead of afterupdate. HTH


Thanks Stuart, but the Click event still still returns a null value - the
same as KeyDown.
--
Bob Darlington
Brisbane

Reply With Quote
  #4  
Old   
Douglas J Steele
 
Posts: n/a

Default Re: List Box KeyDown Behaviour - 07-21-2011 , 04:25 PM



You sure about "Before the event triggers, the list box has a non null
value"?

At least in previous versions of Access, a multi-select list box always
returns a Null value, even if only a single item is selected. The only way
to address its values was through its ItemsSelected collection.


"Bob Darlington" wrote in message
news:4e2769c5$0$22474$afc38c87 (AT) news (DOT) optusnet.com.au...

I'm using an unbound multi select list box in an Access 2010 accdb.
I want to apply a filter to the form so that it displays data for the
currently selected row in the list box when I move from row to row in the
list box using the down arrow key.
(Note: I can do the same thing without a problem using the After Update
event for the list box when a row is selected using the mouse, but I also
want to provide the ability to use the keyboard only.)

But when the arrow down keyboard key is used, the after update event doesn't
trigger until after the focus moves to the next row, so that the form
displays the data for the previously selected row.

I've tried using the following in the KeyDown event for the list box:
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
MsgBox Me!lstLAN
End If
Before the event triggers, the list box has a non null value, and the arrow
down does move to the next row. But the code generates a null value even
though the focus has moved to the next row.

I really don't understand why the afterupdate behaviour should be different
for mouse clicking vs arrow down, but I would like to be enlightened.
Does anyone have an alternative solution for what I'm trying to achieve.

Bob Darlington
Brisbane

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

Default Re: List Box KeyDown Behaviour - 07-21-2011 , 05:34 PM



Thanks Douglas,
I should have said 'when' not 'before'. The null occurs at the MsgBox line
in the code snip I posted.
I wasn't aware of the null value being returned by a multi select list box
even with a single item is selected, so thanks for the info. I still don't
understand why though.
At any rate, I think I've got a way around my problem, which I'll post here
later, if it tests OK.

--
Bob Darlington
Brisbane
"Douglas J Steele" <NOSPAM_djsteele (AT) NOSPAM_gmail (DOT) com> wrote

Quote:
You sure about "Before the event triggers, the list box has a non null
value"?

At least in previous versions of Access, a multi-select list box always
returns a Null value, even if only a single item is selected. The only way
to address its values was through its ItemsSelected collection.


"Bob Darlington" wrote in message
news:4e2769c5$0$22474$afc38c87 (AT) news (DOT) optusnet.com.au...

I'm using an unbound multi select list box in an Access 2010 accdb.
I want to apply a filter to the form so that it displays data for the
currently selected row in the list box when I move from row to row in the
list box using the down arrow key.
(Note: I can do the same thing without a problem using the After Update
event for the list box when a row is selected using the mouse, but I also
want to provide the ability to use the keyboard only.)

But when the arrow down keyboard key is used, the after update event
doesn't
trigger until after the focus moves to the next row, so that the form
displays the data for the previously selected row.

I've tried using the following in the KeyDown event for the list box:
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
MsgBox Me!lstLAN
End If
Before the event triggers, the list box has a non null value, and the
arrow
down does move to the next row. But the code generates a null value even
though the focus has moved to the next row.

I really don't understand why the afterupdate behaviour should be
different
for mouse clicking vs arrow down, but I would like to be enlightened.
Does anyone have an alternative solution for what I'm trying to achieve.

Bob Darlington
Brisbane


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

Default Re: List Box KeyDown Behaviour - 07-21-2011 , 05:45 PM



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

Quote:
I'm using an unbound multi select list box in an Access 2010 accdb.
I want to apply a filter to the form so that it displays data for the
currently selected row in the list box when I move from row to row in the
list box using the down arrow key.
(Note: I can do the same thing without a problem using the After Update
event for the list box when a row is selected using the mouse, but I also
want to provide the ability to use the keyboard only.)

But when the arrow down keyboard key is used, the after update event
doesn't trigger until after the focus moves to the next row, so that the
form displays the data for the previously selected row.

I've tried using the following in the KeyDown event for the list box:
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
MsgBox Me!lstLAN
End If
Before the event triggers, the list box has a non null value, and the
arrow down does move to the next row. But the code generates a null value
even though the focus has moved to the next row.

I really don't understand why the afterupdate behaviour should be
different for mouse clicking vs arrow down, but I would like to be
enlightened.
Does anyone have an alternative solution for what I'm trying to achieve.

Bob Darlington
Brisbane

I've come up with a solution (albeit a bit clunky) to my problem which
others might be interested in.

'Set module level variables:
Dim mIndex as Integer, mblnKeyDown as boolean

'In the list box KeyDown event:
If KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
mblnKeyDown = True
If KeyCode = vbKeyDown Then mIndex = Me!MyListBox.ListIndex + 1 Else
mIndex = Me!MyListBox.ListIndex - 1
End If

'Then, in the list box AfterUpdate event:
If mblnKeyDown Then
DoCmd.ApplyFilter , "LAN = " & Me!MyListBox.ItemData(mIndex)
mblnKeyDown = False
End If

--
Bob Darlington
Brisbane

Reply With Quote
  #7  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: List Box KeyDown Behaviour - 07-22-2011 , 04:15 PM



"Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote in
news:4e28a95a$0$2444$afc38c87 (AT) news (DOT) optusnet.com.au:

Quote:
I wasn't aware of the null value being returned by a multi select
list box even with a single item is selected, so thanks for the
info. I still don't understand why though.
A multiselect listbox has no value because its selection is a
collection. How could it possibly have a value in that case?

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

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.