From: The Frog on
Hi Everyone,

I am stumped. I have a form with multiple listboxes (cascaded if you
will) that 'lead' to a final listbox and under this listbox is a
textbox. On the final listbox (lstProduct), when clicking with the
mouse to select a row, the subform shows the related records from a
table. So far so good. I have tried to implement a set of 'rapid'
keyboard controls to allow a user to jump around the form without
using the mouse. This is where it gets weird....

For the cascaded listboxes this works perfectly. For the lstProduct
control I am having a problem that when a row is selected, the related
data shows up in the subform, but instead of the focus being set to
the textbox (txtProduct) - as it does with the mouse - it is jumping
to the subform. I am using the KeyDown event on both the txtProduct
and lstProduct controls, and the keypress is being 'captured' in the
event (the keycodes are correct). The last lines of code in the Up
Cursor or Down Cursor keys (38 for up and 40 for down) are to set the
focus to the txtProduct control. It just isnt happening. When stepping
through the code the .SetFocus is being called but it just isnt going
to the correct control.

My code on one of the events is as follows:

If lstProduct.ListCount = 0 Then Exit Sub
If lstProduct.ListIndex <= 0 Then Exit Sub
lstProduct.Selected(lstProduct.ListIndex - 1) = True
txtProduct.SetFocus
txtProduct.Value = lstProduct.Column(0, lstProduct.ListIndex)

Nothing special there. I am guessing that there is a complication when
involving the subform that it takes focus when it refreshes /
requeries the underlying table for the associated data, and doesnt
return focus to the main form and hence the setfocus call I am making
doesnt achieve anything because the focus has changed after that is
set.

I need to keep the subform able to be tabbed to (ie/ tabstop still
works), but not to have focus when changing records / rows in the
lstProduct control. Cany anyone point me in the right direction on
this?

Any help appreciated.

Cheers

The Frog
(A2003)
From: The Frog on
Oh yeah,

If it makes any difference or not here is the code for the lstProduct
OnClick event:

If lstProduct.ListCount = 0 Then
lstProduct.Selected(-1) = True
Exit Sub
End If

txtProduct.Value = lstProduct.Column(0, lstProduct.ListIndex)

subVariety.Enabled = True

txtProduct.SetFocus

Cheers

The Frog
From: Stuart McCall on
"The Frog" <mr.frog.to.you(a)googlemail.com> wrote in message
news:6745b7fa-4d4c-49e8-aeb8-f633612e3750(a)i25g2000yqm.googlegroups.com...
> Hi Everyone,
>
> I am stumped. I have a form with multiple listboxes (cascaded if you
> will) that 'lead' to a final listbox and under this listbox is a
> textbox. On the final listbox (lstProduct), when clicking with the
> mouse to select a row, the subform shows the related records from a
> table. So far so good. I have tried to implement a set of 'rapid'
> keyboard controls to allow a user to jump around the form without
> using the mouse. This is where it gets weird....
>
> For the cascaded listboxes this works perfectly. For the lstProduct
> control I am having a problem that when a row is selected, the related
> data shows up in the subform, but instead of the focus being set to
> the textbox (txtProduct) - as it does with the mouse - it is jumping
> to the subform. I am using the KeyDown event on both the txtProduct
> and lstProduct controls, and the keypress is being 'captured' in the
> event (the keycodes are correct). The last lines of code in the Up
> Cursor or Down Cursor keys (38 for up and 40 for down) are to set the
> focus to the txtProduct control. It just isnt happening. When stepping
> through the code the .SetFocus is being called but it just isnt going
> to the correct control.
>
> My code on one of the events is as follows:
>
> If lstProduct.ListCount = 0 Then Exit Sub
> If lstProduct.ListIndex <= 0 Then Exit Sub
> lstProduct.Selected(lstProduct.ListIndex - 1) = True
> txtProduct.SetFocus
> txtProduct.Value = lstProduct.Column(0, lstProduct.ListIndex)
>
> Nothing special there. I am guessing that there is a complication when
> involving the subform that it takes focus when it refreshes /
> requeries the underlying table for the associated data, and doesnt
> return focus to the main form and hence the setfocus call I am making
> doesnt achieve anything because the focus has changed after that is
> set.
>
> I need to keep the subform able to be tabbed to (ie/ tabstop still
> works), but not to have focus when changing records / rows in the
> lstProduct control. Cany anyone point me in the right direction on
> this?
>
> Any help appreciated.
>
> Cheers
>
> The Frog
> (A2003)

This is a guess. When you process the KeyCode in your KeyDown event, are you
'throwing away' the keypress? (KeyCode = 0). If not then you should,
otherwise the keypress is left in the windows message queue and thus will
affect the UI.


From: The Frog on
I did not know this! I will give this a crack and see how it goes.
This would make a lot of sense given the behaviour. Thankyou
Stuart :-)

Cheers

The Frog
From: The Frog on
OK, I gave this a shot and have not had any success. I decided to test
what is going on a little further, and placed a stop call in each of
the keydown, keyup and keypress events. This is what I found: the
first time the down cursor key is pressed the control works as
expected, and (i dont know why) but the controls click event is also
fired. The second time the cursor key is pressed there is no
recognition of the stop call at all - it seems that none of the events
are firing! The focus is then set to the sub form.

I am going to hazard a guess here and assume that somewhere, somehow
the form is fundamentally broken. I will scrap it and replace it with
a new one with the same setup. Wont take too long. Extremely weird
thing to watch in the debugger / code window.......

If anyone else has seen this then please let me know!

Cheers

The Frog