1

I'm building a combobox with the following:

Select 1 or 2 seats: 1 2 

And I need to show 1 or 2 as selected depending on the result of a query.

How can I do that?

I have done so far:

SQL = " SELECT numberOfSeats FROM mytable " SQL = SQL & " WHERE userID ='" SQL = SQL & txtuserID.Text & "'" Set auxRes = UAN.OpenResultset(SQL, rdOpenDynamic, rdConcurValues, 0) cmbNumberOfSeats.Clear cmbNumberOfSeats.AddItem "Select 1 or 2 seats" cmbNumberOfSeats.AddItem "1" cmbNumberOfSeats.AddItem "2" 

Thanks!!

1

1 Answer 1

2

You can use the ListIndex property of the ComboBox control to get / set the index of the selected item. You use it like so:

Dim nSelectedIndex As Long nSelectedIndex = cmbNumberOfSeats.ListIndex If (nSelectedIndex < 0) Then 'No selected item in the combo box Else 'There's a selected item, handle it End If 

To set the selected item:

cmbNumberOfSeats.ListIndex = nNewSelectedIndex 

The index of the first item is 0; when there's no selection, ListIndex returns -1.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.