Listbox control on Form Open (1 Viewer)

billmh

New member
Local time
Today, 21:54
Joined
Sep 23, 2011
Messages
5
I have a form that has two list boxes and a textbox. When the form opens The first item is selected in the first listbox which lists related items in the second and the first item is selected in that lstbox, which puts a value to the textbox.

All works as it should on opening. I can see the first listbox has the focus and the first items are highlighted in both listboxes and an entry is in the texbox. The query for these boxes are established in the On Open of the form.

If I use the down arrow key, the _Click event is fired for the first list box. Which should select the second item and update the following boxes. However, the test for the selected item is still the first item in the list so, the following boxes remain the same. If I press the down arrow a second time everything updates accordingly.

Its like the listbox has the focus, but the first item does not, though it is highlighted. A similar thing happens if I TAB from the first box to the second and then hit the down arrow key there. I have to do it twice.

Here is the On Open code: Note the LstTrailer is setup by a default query for the listbox

Me.lstTrailer.Selected(0) = True

Trailer = Me.lstTrailer.Column(0)

(Tubelst is a query that builds the list for the second listbox based on TRAILER)

Me.lstTubes.RowSource = Tubelst
Me.lstTubes.Selected(0) = True

Me.txtTrTubeCom = Me.lstTubes.Column(1) ' txtbox value entered

The _Click event for the the first listbox lstTrailer is the same code as above. It all works well with subsequent arrow keystrokes. Just not the first.
 

RuralGuy

AWF VIP
Local time
Today, 12:54
Joined
Jul 2, 2005
Messages
13,825
THe Open Event is too early in the process to reference controls on a form. You will want to use the OnLoad event.
 

billmh

New member
Local time
Today, 21:54
Joined
Sep 23, 2011
Messages
5
Gosh! I cannot believe I did not try that. Simple fix and everything works just fine. Thanks.
 

Users who are viewing this thread

Top Bottom