Query based on a combobox on a subform in a subform

A

a.t.brooks

Hello
I have a subform witin a subform.
In that subform are two comboboxes.
I would like to know how to get the list in combobox 2 to be dependent
on combobox 1.
Specifically, box 1 is measurement_unit_type with values: "Time",
"Distance", "Mass" etc..
Once this is selected. I would then like the contents of box 2 to be
filtered so that if, for example "Time" is selected, the values would
be "seconds", "hours", "days", if Mass is seleted, then the values
would be "grams", "kilograms", etc..
I have made a table as such;

Time | seconds
Time | hours
Time | days
Mass | miligrams
Mass | grams
Mass | kilograms
....

The problem, I think is that the combo boxes are in a subform on a
subform.
Does anyone know how I could get this to work?
I've tied building a query with the following as criteria, but it
doesn't work

Forms![frm_mainform].[frm_subform1].[frm_subform2].Form!
[cmb1measurement_unit_type]

Any help would be appreciated
 
J

John W. Vinson

Hello
I have a subform witin a subform.
In that subform are two comboboxes.
I would like to know how to get the list in combobox 2 to be dependent
on combobox 1.
Specifically, box 1 is measurement_unit_type with values: "Time",
"Distance", "Mass" etc..
Once this is selected. I would then like the contents of box 2 to be
filtered so that if, for example "Time" is selected, the values would
be "seconds", "hours", "days", if Mass is seleted, then the values
would be "grams", "kilograms", etc..
I have made a table as such;

Time | seconds
Time | hours
Time | days
Mass | miligrams
Mass | grams
Mass | kilograms
...

The problem, I think is that the combo boxes are in a subform on a
subform.
Does anyone know how I could get this to work?
I've tied building a query with the following as criteria, but it
doesn't work

Forms![frm_mainform].[frm_subform1].[frm_subform2].Form!
[cmb1measurement_unit_type]

Any help would be appreciated

Try

Forms![frm_mainform].[frm_subform1].Form![frm_subform2].Form!
[cmb1measurement_unit_type]

using the actual names of the Subform controls (which may or may not be the
same as the name of the form within that control); or explicitly build a SQL
string as a rowsource. For instance, in the Afterupdate event of combo box 1
(which I'll guess is named cboUnit_Type, while the other is named cboUnit):

Private Sub cboUnit_Type_AfterUpdate()
Dim strSQL As String
strSQL = "SELECT Unit FROM Units WHERE Unit_Type = '" _
& Me!cboUnit_Type & "' ORDER BY Unit;"
Me!cboUnit.RowSource = strSQL
End Sub

Error trapping, checking for nonexistant unit types, etc. left as an
exercise...

John W. Vinson [MVP]
 
A

a.t.brooks

Hi John
I've got it working using your SQL method. I had to tweek the code a
little by changing Me!cboUnit_Type to Me.cboUnit_Type.Text and it
seems to work really nicely.
Thanks
Tony
 
J

John W. Vinson

I've got it working using your SQL method. I had to tweek the code a
little by changing Me!cboUnit_Type to Me.cboUnit_Type.Text and it
seems to work really nicely.

Odd. The .Text and the (default, hence not specified) .Value properties should
be identical in the AfterUpdate event. Did you use some other event?

If it's working though... good enough!

John W. Vinson [MVP]
 

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