Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox default selection

Status
Not open for further replies.

reimbursement

Programmer
Joined
May 5, 2003
Messages
7
Location
US
I have multiple listboxes on a userform to get the users input on what to include in a autofilter list. The listboxes allow for multiple selections. Is there a way to set the first item in the list as the default if nothing is selected?
 
Well, maybe this will help ... I have done this in Access by adding this line to the open event of the form containing the listbox. This selects the first row in the list:

Me.LstDescription.Selected(0) = True

Hope this is what you want!
 
The ListIndex property sets the list's selection, first item is 0:
[tt]ListBox.ListIndex = 1[/tt]
selects the second value in list box named ListBox.

combo
 
Hi reimbursement,

To expand on the other replies a little. Firstly you need to check whether or not there is a selection and then you can either set the default selection (which seems like overkill) or just use the value you want for your further processing.

Code:
If Me![
Code:
ListBoxName
Code:
].ItemsSelected.Count = 0 Then
Code:
YourVar
Code:
 = Me![
Code:
ListBoxName
Code:
].ItemData(0)
Code:
' To use the first item
Code:
    Me![List0].Selected(0) = True
Code:
         ' To select the first item
Code:
End If

Enjoy
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top