Listbox - nav to rec by keystroke does not fire AfterUpdate 
Author Message
 Listbox - nav to rec by keystroke does not fire AfterUpdate

The Access listbox has the handy default behavior of navigating to the
first rec whose first character that matches the key you've pressed.
Like if I type "c" it will navigate to the first entry that starts with
"c". However the AfterUpdate event does not fire. Is there any way to
get it to? I'd like to avoid keypress trapping if I could but that looks
like the only option at this point.


Fri, 08 Jul 2005 16:36:02 GMT  
 Listbox - nav to rec by keystroke does not fire AfterUpdate
kiln

the way your question is phrased suggests that you are expecting the
AfterUpdate event to fire after pressing a single keystroke ("c", in your
example).  The OnChange event is for this, the AfterUpdate follows the
Before Update when you *leave* the control by tabbing out, clicking on
another control etc.

What do you want to do in your "AfterUpdate" event?

Andy


Quote:
> The Access listbox has the handy default behavior of navigating to the
> first rec whose first character that matches the key you've pressed.
> Like if I type "c" it will navigate to the first entry that starts with
> "c". However the AfterUpdate event does not fire. Is there any way to
> get it to? I'd like to avoid keypress trapping if I could but that looks
> like the only option at this point.



Fri, 08 Jul 2005 17:51:57 GMT  
 Listbox - nav to rec by keystroke does not fire AfterUpdate
Hi Andy

Thanks for responding. But, a listbox doesn't have an OnChange event.
Also, it's more accurate to say that the AfterUpdate event fires when a
new value is "selected" in the listbox, for instance by clicking, not
when one tabs off of the listbox. That behavior is relevant to the issue
I'm working on.

In this app, the listbox provides a way to select a record, after which
that record's details are displayed in a subform. A commonplace
scenario. It all works fine, it's just that when the users nav by
pressing "r" for instance, and the first "r" record is navigated to in
the listbox, the users expect the detail rec to show in the subform. It
does not, because the afterupdate event that populates the subform
hasn't fired.

What is particularly awkward is that if you press "r" then "c" then "b",
the afterupdate event does fire; but it fires for the listbox entry that
it just left, not the one it arrived at. So, what shows in the detail
subform is first no rec, then the first "r" rec, then the first "c" rec.
It's always lagging by one step.

The visual clues to the "selected" state of the listbox control are also
misleading. After selecting "b" or whatever, the first "b" rec is
apparently selected, that it's colors are reversed, and it gets the
dotted line around it. Looks just like it was clicked. But no
AfterUpdate event.

This listbox is set to multiselect extended, but the behavior noted is
the same in any select mode.



Quote:
> kiln

> the way your question is phrased suggests that you are expecting the
> AfterUpdate event to fire after pressing a single keystroke ("c", in your
> example).  The OnChange event is for this, the AfterUpdate follows the
> Before Update when you *leave* the control by tabbing out, clicking on
> another control etc.

> What do you want to do in your "AfterUpdate" event?

> Andy



> > The Access listbox has the handy default behavior of navigating to the
> > first rec whose first character that matches the key you've pressed.
> > Like if I type "c" it will navigate to the first entry that starts with
> > "c". However the AfterUpdate event does not fire. Is there any way to
> > get it to? I'd like to avoid keypress trapping if I could but that looks
> > like the only option at this point.



Sat, 09 Jul 2005 01:12:26 GMT  
 Listbox - nav to rec by keystroke does not fire AfterUpdate
kiln

Sorry about my wrong advice, I've never used a list box (always use combos
instead due to space) and I assumed (wrongly) that they would have the same
events as other controls.

However, I've just had a play with a ListBox (in Multi-extended mode) and
cannot reproduce the behaviour you describe.  The order of events for the
list box is OnEnter, OnGotFocus and then after clicking a selection the
OnMouseDown, or typing a letter the OnKeyDown, OnKeyPress, and finally the
OnBeforeUpdate, On AfterUpdate, OnClick.  The item shows as highlighted in
both mouse click and key press methods of selection.

I'm using A2K with the MSO SR2 applied by the way.

I'd suggest disabling all event code from your listbox first and check
whether the listbox behaves as it should and then enable an event code one
at a time to, hopefully, find what is causing the mis-functioning of the
listbox

HTH

Andy


Quote:
> Hi Andy

> Thanks for responding. But, a listbox doesn't have an OnChange event.
> Also, it's more accurate to say that the AfterUpdate event fires when a
> new value is "selected" in the listbox, for instance by clicking, not
> when one tabs off of the listbox. That behavior is relevant to the issue
> I'm working on.

> In this app, the listbox provides a way to select a record, after which
> that record's details are displayed in a subform. A commonplace
> scenario. It all works fine, it's just that when the users nav by
> pressing "r" for instance, and the first "r" record is navigated to in
> the listbox, the users expect the detail rec to show in the subform. It
> does not, because the afterupdate event that populates the subform
> hasn't fired.

> What is particularly awkward is that if you press "r" then "c" then "b",
> the afterupdate event does fire; but it fires for the listbox entry that
> it just left, not the one it arrived at. So, what shows in the detail
> subform is first no rec, then the first "r" rec, then the first "c" rec.
> It's always lagging by one step.

> The visual clues to the "selected" state of the listbox control are also
> misleading. After selecting "b" or whatever, the first "b" rec is
> apparently selected, that it's colors are reversed, and it gets the
> dotted line around it. Looks just like it was clicked. But no
> AfterUpdate event.

> This listbox is set to multiselect extended, but the behavior noted is
> the same in any select mode.



> > kiln

> > the way your question is phrased suggests that you are expecting the
> > AfterUpdate event to fire after pressing a single keystroke ("c", in
your
> > example).  The OnChange event is for this, the AfterUpdate follows the
> > Before Update when you *leave* the control by tabbing out, clicking on
> > another control etc.

> > What do you want to do in your "AfterUpdate" event?

> > Andy



> > > The Access listbox has the handy default behavior of navigating to the
> > > first rec whose first character that matches the key you've pressed.
> > > Like if I type "c" it will navigate to the first entry that starts
with
> > > "c". However the AfterUpdate event does not fire. Is there any way to
> > > get it to? I'd like to avoid keypress trapping if I could but that
looks
> > > like the only option at this point.



Sat, 09 Jul 2005 19:45:12 GMT  
 Listbox - nav to rec by keystroke does not fire AfterUpdate
Thanks for following me on this. To see what I'm talking about, do the
following:

Create a table tlbLetter with a single text field, and add 5 records,
with each rec holding a single letter (A, B, C, D, E). Create new form.
Place a listbox on the form, call it lstLetter, set it to Multi-Select
Extended and make it's rowsource tlbLetter. Place a textbox on the form
called txtValue. Here is the code for the after update event.

Private Sub lstLetter_AfterUpdate()
   Dim lst As ListBox
   Dim strValue As String
   Set lst = lstLetter

   If lst.ItemsSelected.Count > 0 Then
      strValue = lst.ItemData(lst.ItemsSelected(0))
      txtValue = strValue
   Else
      MsgBox "None Sel"
   End If
End Sub

If you then run the form, you'll see that if you click on the list
entries, the letter you'd expect gets put into txtValue. If however you
use the arrow keys (or any other key-based nav technique) txtValue is
always updated with the value in the row you just left.

If the listbox is set to disallow multiselect, you don't see this sych
failuer if you use the simple

   txtValue = lstLetter

We're on the same ver of Access, BTW.



Quote:
> kiln

> Sorry about my wrong advice, I've never used a list box (always use combos
> instead due to space) and I assumed (wrongly) that they would have the same
> events as other controls.

> However, I've just had a play with a ListBox (in Multi-extended mode) and
> cannot reproduce the behaviour you describe.  The order of events for the
> list box is OnEnter, OnGotFocus and then after clicking a selection the
> OnMouseDown, or typing a letter the OnKeyDown, OnKeyPress, and finally the
> OnBeforeUpdate, On AfterUpdate, OnClick.  The item shows as highlighted in
> both mouse click and key press methods of selection.

> I'm using A2K with the MSO SR2 applied by the way.

> I'd suggest disabling all event code from your listbox first and check
> whether the listbox behaves as it should and then enable an event code one
> at a time to, hopefully, find what is causing the mis-functioning of the
> listbox

> HTH

> Andy



> > Hi Andy

> > Thanks for responding. But, a listbox doesn't have an OnChange event.
> > Also, it's more accurate to say that the AfterUpdate event fires when a
> > new value is "selected" in the listbox, for instance by clicking, not
> > when one tabs off of the listbox. That behavior is relevant to the issue
> > I'm working on.

> > In this app, the listbox provides a way to select a record, after which
> > that record's details are displayed in a subform. A commonplace
> > scenario. It all works fine, it's just that when the users nav by
> > pressing "r" for instance, and the first "r" record is navigated to in
> > the listbox, the users expect the detail rec to show in the subform. It
> > does not, because the afterupdate event that populates the subform
> > hasn't fired.

> > What is particularly awkward is that if you press "r" then "c" then "b",
> > the afterupdate event does fire; but it fires for the listbox entry that
> > it just left, not the one it arrived at. So, what shows in the detail
> > subform is first no rec, then the first "r" rec, then the first "c" rec.
> > It's always lagging by one step.



Sun, 10 Jul 2005 10:34:44 GMT  
 Listbox - nav to rec by keystroke does not fire AfterUpdate
kiln

Using your code I can reproduce the problem - weird.  The problem is caused
by the ItemsSelected.Count not being updated when using the nav/character
keys. I tried using the code on the OnClick event which fires after the
AfterUpdate but got the same result.

At the moment I can't think or a reason why but I'll try working on a
solution in the meantime.

I'd recommend reposting the problem as laid out below with a subject of
"Listbox ItemsSelected not updated when using keyboard" (or something
similar) and see if one of the MSVPs picks it up

Sorry I'm not able to give a definitive answer :{

Andy


Quote:
> Thanks for following me on this. To see what I'm talking about, do the
> following:

> Create a table tlbLetter with a single text field, and add 5 records,
> with each rec holding a single letter (A, B, C, D, E). Create new form.
> Place a listbox on the form, call it lstLetter, set it to Multi-Select
> Extended and make it's rowsource tlbLetter. Place a textbox on the form
> called txtValue. Here is the code for the after update event.

> Private Sub lstLetter_AfterUpdate()
>    Dim lst As ListBox
>    Dim strValue As String
>    Set lst = lstLetter

>    If lst.ItemsSelected.Count > 0 Then
>       strValue = lst.ItemData(lst.ItemsSelected(0))
>       txtValue = strValue
>    Else
>       MsgBox "None Sel"
>    End If
> End Sub

> If you then run the form, you'll see that if you click on the list
> entries, the letter you'd expect gets put into txtValue. If however you
> use the arrow keys (or any other key-based nav technique) txtValue is
> always updated with the value in the row you just left.

> If the listbox is set to disallow multiselect, you don't see this sych
> failuer if you use the simple

>    txtValue = lstLetter

> We're on the same ver of Access, BTW.



> > kiln

> > Sorry about my wrong advice, I've never used a list box (always use
combos
> > instead due to space) and I assumed (wrongly) that they would have the
same
> > events as other controls.

> > However, I've just had a play with a ListBox (in Multi-extended mode)
and
> > cannot reproduce the behaviour you describe.  The order of events for
the
> > list box is OnEnter, OnGotFocus and then after clicking a selection the
> > OnMouseDown, or typing a letter the OnKeyDown, OnKeyPress, and finally
the
> > OnBeforeUpdate, On AfterUpdate, OnClick.  The item shows as highlighted
in
> > both mouse click and key press methods of selection.

> > I'm using A2K with the MSO SR2 applied by the way.

> > I'd suggest disabling all event code from your listbox first and check
> > whether the listbox behaves as it should and then enable an event code
one
> > at a time to, hopefully, find what is causing the mis-functioning of the
> > listbox

> > HTH

> > Andy



> > > Hi Andy

> > > Thanks for responding. But, a listbox doesn't have an OnChange event.
> > > Also, it's more accurate to say that the AfterUpdate event fires when
a
> > > new value is "selected" in the listbox, for instance by clicking, not
> > > when one tabs off of the listbox. That behavior is relevant to the
issue
> > > I'm working on.

> > > In this app, the listbox provides a way to select a record, after
which
> > > that record's details are displayed in a subform. A commonplace
> > > scenario. It all works fine, it's just that when the users nav by
> > > pressing "r" for instance, and the first "r" record is navigated to in
> > > the listbox, the users expect the detail rec to show in the subform.
It
> > > does not, because the afterupdate event that populates the subform
> > > hasn't fired.

> > > What is particularly awkward is that if you press "r" then "c" then
"b",
> > > the afterupdate event does fire; but it fires for the listbox entry
that
> > > it just left, not the one it arrived at. So, what shows in the detail
> > > subform is first no rec, then the first "r" rec, then the first "c"
rec.
> > > It's always lagging by one step.



Mon, 11 Jul 2005 09:57:58 GMT  
 Listbox - nav to rec by keystroke does not fire AfterUpdate
I appreciate the fact that you took the time to look into this issue.
Pretty odd.

I hate to clutter up the list with another post (I tried several times
before and you were the first one to respond) but I may do so after
giving whomever another day or so to join this conversation.



Quote:
> kiln

> Using your code I can reproduce the problem - weird.  The problem is caused
> by the ItemsSelected.Count not being updated when using the nav/character
> keys. I tried using the code on the OnClick event which fires after the
> AfterUpdate but got the same result.

> At the moment I can't think or a reason why but I'll try working on a
> solution in the meantime.

> I'd recommend reposting the problem as laid out below with a subject of
> "Listbox ItemsSelected not updated when using keyboard" (or something
> similar) and see if one of the MSVPs picks it up

> Sorry I'm not able to give a definitive answer :{

> Andy



Tue, 12 Jul 2005 01:22:39 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Listbox - nav to rec by keystroke does not fire AfterUpdate

2. Listbox - nav to rec by keystroke does not fire AfterUpdate

3. Listbox - nav to rec by Alpha does not fire AfterUpdate

4. AfterUpdate and LostFocus Events do not fire

5. Form not firing AfterUpdate

6. AfterUpdate of form not firing in a Project

7. AfterUpdate of form not firing in a Project

8. Remove New Rec But from Nav Buts

9. Listbox highlight of selected rec does not clear

10. Keystrokes Keystrokes Keystrokes


 
Powered by phpBB® Forum Software © phpBB Group