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!

combobox property

Status
Not open for further replies.

littledude

Programmer
Apr 24, 2002
2
0
0
US
i have a combobox that only lists one option instead of
all of them. I have stepped through the code and it gets
all of the info i need, but only displays the last one.



If Not rs.EOF Then
Do While Not rs.EOF
Me.cboBox = rs.Fields(2)
rs.MoveNext
Loop
End If
 
You are setting the value of the ComboBox to each value in turn. At the end of the loop the last record will be displayed. Access Combos need to be based on a Table, Query or Value List, so can't you use the SQL for whatever recordset you are looping through to set the Source of the Combo. Make it Multi Column and hide all the columns you don't want.

rgds
Andy
 
First, you have a basic mistake in your code:

cboBox.RowSourceType = "Value List"
If Not rs.EOF Then
Do While Not rs.EOF
cboBox.RowSource = cboBox.RowSource & rs.Fields(2) & ";"
rs.MoveNext
Loop
End If
When you write it like this, than the values will be added to the comboBox one by one.
Basicly, I don't understand why do you need to do it in VBA when you can set it as default properties of the comboBox, but you can do it the way I showed it and it should work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top