![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
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) |
#4
| |||
| |||
|
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Alrighty then......... Form is rebuilt. Events are working. Setting the keycode = 0 at the end if each desired keydown event option stops the subform getting the focus. Final code as an example for the cursor down key on the KeyDown event is as follows: If lstProduct.ListCount = 0 Then Exit Sub If lstProduct.ListIndex >= lstProduct.ListCount - 1 Then Exit Sub lstProduct.Selected(lstProduct.ListIndex + 1) = True lstProduct.Value = lstProduct.Column(lstProduct.BoundColumn - 1, lstProduct.ListIndex) txtProduct.SetFocus txtProduct.Value = lstProduct.Column(0, lstProduct.ListIndex) KeyCode = 0 Works perfectly Thankyou for your help. I would never have guessed the keycode = 0 thing. It was also necessary to set the value property of the listbox in the code so that the subform updated automatically (if anyone is interested). If I didnt set this the subform didnt show the related records. Thankyou for all your help, I really appreciate it. Cheers The Frog |
![]() |
| Thread Tools | |
| Display Modes | |
| |