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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting an item from a combo box with VBA

Status
Not open for further replies.

Cachelot

Programmer
Jan 30, 2001
15
0
0
CA
Here is the situation, I use the following code to set the RowSource of a combo box:

PartQuery = "SELECT [Parts].[PartID], [Parts].[Part] FROM Parts WHERE [Parts].[PartID]= 1 Or [Parts].[SubCatID]=" & Me!cmbSubCategory & " ORDER BY [Parts].[Part];"

Me!cmbPart.RowSource = PartQuery

This work fine, but there are no item selected in the combo box. I would like to select (as a default) the first item of the list. How can I do that??

Thanks for your help in advance.
 
To select the first item in the list, you can set the BoundColumn property to 0 (zero) or you can set the ItemData method to 0 (zero):

=cboYourComboBox.ItemDate(0)

Hope that is what you were looking for... Terry M. Hoey
th3856@txmail.sbc.com
While I don't mind e-mail messages, please post all questions in these forums for the benefit of all members.
 
add this to the code prior to the statement where you set PartQuery


If IsNull(Me!cmbSubCategory) Then
Me!cmbSubCategory = Me!cmbSubCategory.ItemData(0)
End If

PaulF
 
The use of ItemData(0) did not work for me, however I was told else where that I could use Me.cmbSubCategory.ListIndex = 0, which works for me, but after this code I want the focus to be removed from this combo box and be set on a text box. I tried the follpwing code:

Me.cmbSubCategory.ListIndex = 0
Me.txtPart.SetFocus

But it does work the focus stays on the cmdSubCategory combo box. What can I do to fixe this???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top