Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / August 2007

Tip: Looking for answers? Try searching our database.

Query based on a combobox on a subform in a subform

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
a.t.brooks@talk21.com - 05 Aug 2007 22:15 GMT
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
John W. Vinson - 05 Aug 2007 23:17 GMT
>Hello
>I have a subform witin a subform.
[quoted text clipped - 27 lines]
>
>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.t.brooks@talk21.com - 06 Aug 2007 12:52 GMT
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
John W. Vinson - 06 Aug 2007 17:33 GMT
>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]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.