Combo Boxes

  • Thread starter Thread starter MWilson
  • Start date Start date
M

MWilson

I have two combo boxes, Division & Branches based on
tables of the same names. When I click on a particular
division, I only want the braches related to that division
to appear in the Branches box instead of all the branches.
How do I do this.
Thanks
 
For the Branch combo Box set WHERE condition of the
RowSource SQL to use the value of the Division comboBox
e.g.

"SELECT etc WHERE {divisionId} = " & {divisionCombo}.Value

In the AfterUpdate event handler for the Divison comboBox,
put a call to Requery the Branch comboBox
e.g.
{branchCombo}.Requery

In both places, you should replace the {} with your own
column and control names.

Hope That Helps
Gerald Stanley MCSD
 
No Help
-----Original Message-----
For the Branch combo Box set WHERE condition of the
RowSource SQL to use the value of the Division comboBox
e.g.

"SELECT etc WHERE {divisionId} = " & {divisionCombo}.Value

In the AfterUpdate event handler for the Divison comboBox,
put a call to Requery the Branch comboBox
e.g.
{branchCombo}.Requery

In both places, you should replace the {} with your own
column and control names.

Hope That Helps
Gerald Stanley MCSD
.
 
You want to restrict the dropdown list in the second combo
box based upon the selection made in the first combo box.
The combobox property that determines what is shown in the
dropdown list is called RowSource, which needs to be
populated with an SQL statement telling Access what to show
in the dropdown list and where to get it from. Normally
the SQL statement is unqualified, i.e. it will show all
items from the database. In this requirement, the SQL
statement needs to be qualified with a WHERE condition to
take into account the selection from the first combo box.
Where the SQL is generated depends upon whether the form is
for entering new data, amending existing data or searching.
In most cases, it can be put in the AfterUpdate event
handler of the first combo Box; other times, it is best to
put in the GotFocus event handler of the second combo box.
In the simple case where the first combo shows the key
column that links the two combo boxes, the code takes the
form of combo2.RowSource = "SELECT columnNames FROM
tableName WHERE foreignKeyColumnName = " & combo1.value.

Hope This Helps
Gerald Stanley MCSD
 
I have been following this thread with interest. It seems like it covers exactly the things I'm interested in - only, I don't quite understand

Is there any chance you could point me to an example where this whole setup is being used? I think I understand your point - the key thing is to make the application understand you want to query using the data for this particular row, not the more general case. I mean, in Java (where most of my programming experience is) I'd say something like this.division_id

Perhaps it's the semantics of the system I don't understand

Oh, and on a related note, can I put sql into the expression builder?
 
Alister

Let me know which version of Access you are using and I
will send you a sample.

Regards

Gerald Stanley MCSD
-----Original Message-----
I have been following this thread with interest. It seems
like it covers exactly the things I'm interested in - only,
I don't quite understand.
Is there any chance you could point me to an example where
this whole setup is being used? I think I understand your
point - the key thing is to make the application understand
you want to query using the data for this particular row,
not the more general case. I mean, in Java (where most of
my programming experience is) I'd say something like
this.division_id.
 
Back
Top