A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query based on a combobox on a subform in a subform



 
 
Thread Tools Display Modes
  #1  
Old August 5th, 2007, 10:15 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 22
Default Query based on a combobox on a subform in a subform

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

  #2  
Old August 5th, 2007, 11:17 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Query based on a combobox on a subform in a subform

On Sun, 05 Aug 2007 14:15:36 -0700, wrote:

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]
  #3  
Old August 6th, 2007, 12:52 PM posted to microsoft.public.access.forms
[email protected]
external usenet poster
 
Posts: 22
Default Query based on a combobox on a subform in a subform

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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:00 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.