Setting control source for combo box from form code

J

John Kozma

I want to be able to change the control source for a combo box in a form in
response to the user's actions. In particular, I want to change the control
source to a table, to add lines to the list displayed by the combo box
without adding records to the table, or to display expressions. I'm having
difficulty referring to the table. If my database name is db1, the table
name is tableX, and the field from tableX I want to display in the combo box
(comboY) is fieldZ, what would be a statement or statements in the form load
procedure to accomplish this?

Thanks,
John Kozma
 
H

Howard Brody

Dim strSource as Strin
strSource = "SQL string you programatically build based on user selections and database needs;
cboComboY.RowSource = strSourc
cboComboY.Requer


----- John Kozma wrote: ----

I want to be able to change the control source for a combo box in a form i
response to the user's actions. In particular, I want to change the contro
source to a table, to add lines to the list displayed by the combo bo
without adding records to the table, or to display expressions. I'm havin
difficulty referring to the table. If my database name is db1, the tabl
name is tableX, and the field from tableX I want to display in the combo bo
(comboY) is fieldZ, what would be a statement or statements in the form loa
procedure to accomplish this

Thanks
John Kozm
 
T

Thomas Kroljic

John,
I use the following logic to change the recordset in one combo-box based
on
what the user selected in another combo-box:

Me.cbo_category1.RowSource = "SELECT ContactCategories.Category, " &
_
"ContactCategories.SalesPerson FROM " & _
"ContactCategories WHERE " & _
"(((ContactCategories.SalesPerson)= '" & _
Form_frmNewContactList.cbo_employee & "')) " & _
"ORDER BY ContactCategories.Category"

I use the first combo-box (form_frmNewContactList.cbo_employee) as part
of the WHERE
clause in the second combo-box.

Hope this helps,

Thomas J. Kroljic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top