Selecting Item in ListBox with code

  • Thread starter Thread starter Flannel
  • Start date Start date
F

Flannel

I have listbox1 that when I select an item from it, it then
displays items in another listbox2. When I select an item
from listbox1, how can I get it so that the first item in
listbox2 is automatically selected? - thanks
 
I use:

Me.listReports = Me.listReports.Column(0, 0)
Me.listReports.Selected(0) = True


The first line of code might be sufficient, as it simply sets the value of
the listbox.

However, I usually use both...
 
Albert D. Kallal said:
I use:

Me.listReports = Me.listReports.Column(0, 0)
Me.listReports.Selected(0) = True


The first line of code might be sufficient, as it simply sets the
value of the listbox.

However, I usually use both...

I wouldn't use Me.listReports.Column(0, 0), as that will fail if the
bound column isn't Column(0), or if the list box has column headers set
on. I'd use

With Me.listReports
.Value = .ItemData(Abs(.ColumnHeads))
End With

This will work so long as the list box is not multiselect and has any
items in its list. The line setting the .Selected property isn't
necessary in that case. If the list box *is* multiselect, then the
above won't work.
 
Back
Top