I have a table called Customer, with an attribute called CustomerLastName. How do I populate the combo box with the last names from the database into the combo box.
Here is a snippet from one of my own projects. rsCustomers is the recordset. The combo box is named cboCustomers. Feel free to ask for more help if you need.
With rsCustomers
Do Until .EOF
cboCustomers.AddItem !CustName
cboCustomers.ItemData(cboCustomers.NewIndex) = !CustID
.MoveNext
Loop
.MoveFirst
cboCustomers.Text = !CustName
End With
There is a way to do it without any code. Just put a DBCombo box on the form and in the Data Source you put the source of your data, whether it's a data control or SQL Statement or tablename. Your row source is the name of the field that you want displayed.
Here is a breakdown to Omega36 solution without writing any code.
1. Add a datacontrol to your form.
2. For its connect string property, connect to the database that you are using.
3. For its Rowsource property, select the Customer table.
4. Now, set the Data Source property of you combo box to the datacontrol.
5. If all the above steps were correct, you should see a list of the fields from the Customer table in a drop-down list of the rowsource property for the combo box. Now, like Omega36 said, set the rowsource property of the combo box to the CustomerLastName.
yes but data binding is not always the way to go, if you populate the combo box with code you can have more control over it. but you can do it either way. ----------------
Joe
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.