473,385 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access 07 ComboBox Filter results category subcategory type SubType

gcoaster
117 100+
Hello Everyone!

I have a question regarding "cascading combobox(s) list(s)"

I would like:

ComboBox 2 to show results from ComboBox 1's selection,
then ComboBox 4 to show results from ComboBox 3's choice

For Instance these are the combo boxes
[category] [subcategory] [type] [subtype]

This is the sample of choices in the combo boxes
HARDWARE - CABLES - USB - 2.0
HARDWARE - CPU - AMD - AM2

QUESTION(s)

Do I create ONE table for this? OR
Do I create 4 tables = tblcategory tblsubcategory tbltype tblsubtype ?
Do I place a QUERY in the middle of the TABLE(s) and the FORM?

Should I use VBA to make this work?
Should I use sql in the control source to make this work?

What is the best solution? so many answers, so many posts,..
a lookup in a table field.

thank you in advanced!!!

Matt
Oct 4 '07 #1
34 12518
FishVal
2,653 Expert 2GB
Hi, Matt.

So basically you want a tree with "one parent has many childs". You need one tables for this.

Expand|Select|Wrap|Line Numbers
  1. tblCategories
  2. keyCategoryID          Autonumber(Long)    PK
  3. txtCategoryName        Text
  4. keyParentCategory      FK(tblCategories.keyCategoryID)
  5.  
And take a look at Cascading Combo/List Boxes
Oct 4 '07 #2
gcoaster
117 100+
Hello,
thank you for your reply FishVal, I appreciate it.
that article you gave me is excellent.. I found it yesterday.

HOWEVER it deals with 2 comboboxes
Company and Employees

I have 4

category subcategory type subtype

and I really don't know how to make this VBA code go past 2 columns, it only deals with 2.. Company and Employees
would I add another ELSE section? or just make another module for type!?! i think I am getting it!
Expand|Select|Wrap|Line Numbers
  1. Private Sub Company_AfterUpdate()
  2.         With Me![category]
  3.           If IsNull(Me!Company) Then
  4.             .RowSource = ""
  5.           Else
  6.             .RowSource = "SELECT [EmpName] " & _
  7.                          "FROM TblEmployees " &  _
  8.                          "WHERE [ID]=" & Me!Company
  9.           End If
  10.           Call .Requery
  11.         End With
  12.     End Sub
Oct 4 '07 #3
gcoaster
117 100+
And I almost didn't survive until i found this!!!! PRAISE THE LORD!!!

Support WebCast: Microsoft Access: Combo Box Survival Guide
http://support.microsoft.com/default.aspx?kbid=324585
Oct 4 '07 #4
FishVal
2,653 Expert 2GB
Hi, there. I really don't understand your difficulties.
Place the folllowing code in AfterUpdate event handlers of each combo but the last one. Assumed you are going with table structure I suggested in post#2 and combos are 2-column (keyCategoryID, txtCategoryName), the first is bound and invisible (column width is set to 0).

Expand|Select|Wrap|Line Numbers
  1. Private Sub <level N combo>_AfterUpdate()
  2.         With Me![<level N+1 combo>]
  3.           If IsNull(Me![<level N combo>]) Then
  4.             .RowSource = ""
  5.           Else
  6.             .RowSource = "SELECT  keyCategoryID, txtCategoryName " & _
  7.                          "FROM tblCategories " &  _
  8.                          "WHERE keyParentCategory=" & Me![<level N combo>] & ";"
  9.           End If
  10.           Call .Requery
  11.         End With
  12.     End Sub
  13.  
Other options:
  • you have 1 combo which changes it's own RowSource in AfterUpdate to walk down the tree; this case you should think how you want to walk up level one or/and to the topmost categories level
  • you use treeview control to browse through categories
Oct 4 '07 #5
gcoaster
117 100+
Hello FishVal,
thank you for your time.

the table structure you suggested in post#2 is for ONE TABLE.
and that is a table called tblCategories, there is no mention of another table.

the table has 3 columns

1 - keyCategoryID Autonumber(Long) PK
2 - txtCategoryName Text HARDWARE SOFTWARE
3 - keyParentCategory FK(tblCategories.keyCategoryID)

2 would hold HARDWARE SOFTWARE

where would CPU, CD, CABLES go?
in the Foreign Key column? I dont think so? really?
Oct 4 '07 #6
FishVal
2,653 Expert 2GB
Hi, gcoaster.
Expand|Select|Wrap|Line Numbers
  1. keyCategoryID   txtCategoryName  keyParentCategory
  2. 1                 HARDWARE        Null
  3. 2                 SOFTWARE        Null
  4. 3                 CPU             1
  5. 4                 CD              1
  6. 5                 CABLES          1
  7. 6                 Office 2007     2
  8. 7                 USB             5
  9. 8                 USB 2.0         7
  10.  
keyCategoryID - inique category key
txtCategoryName - name of category

so far the categories list is flat, to split it to levels add

keyParentCategory - =keyCategoryID of the parent category, to make it more representative in table view add lookup feature to the field

Retrieve to the topmost combo records where keyParentCategory Is Null.

Still doesn't make you sense?
Oct 4 '07 #7
gcoaster
117 100+
AH HA!!! now I get it! I took one look at it and now I totally understand..
I am visual.. I had to see an example of it to understand. +

however I dont understand what you mean by flat... when you mention
"so far the categories list is flat,"
AND
" to make it more representative in table view add lookup feature to the field"
Oct 4 '07 #8
FishVal
2,653 Expert 2GB
AH HA!!! now I get it! I took one look at it and now I totally understand..
I am visual.. I had to see an example of it to understand.
Thats good.

however I dont understand what you mean by flat... when you mention
"so far the categories list is flat,"
I mean that with the first two fields you get table where all categories are equal, no levels defined. The third field - [keyParentCategory] adds levels.

AND
" to make it more representative in table view add lookup feature to the field"
Make [keyParentCategory] as Number/Long field, then go to "Lookup" tab and set
  • Display Control = Combo Box
  • Row Source Type = Table/Query
  • Row Source = SELECT tblCategories.* FROM tblCategories;
  • Bound Column = 1
  • Column Count = 2
  • Column Widths = 0";2"
  • the rest as you like

this will transform [keyParentCategory] field in table view from textbox to combobox, the drawback is that having added new records you'll need to reopen the table to require the combo.

You may stay without lookup feature and write numbers to [keyParentCategory] field, this case no need in table reopening.

Or you may design form where combo rowsource will be required automatically.
Oct 4 '07 #9
NeoPa
32,556 Expert Mod 16PB
I don't mean to disturb the conversation here, but there is another article (Example Filtering on a Form.) that may also help. It goes through adding multiple ComboBoxes to filter the data as per the selection.
Please ignore if this would only complicate matters, but you may find it helpful.
Oct 4 '07 #10
gcoaster
117 100+
FishVal, you rock..
I am going to print this out, go to the coffee house.. come back and try it!
thank you FishVal.
you ever on the gold coast of Australia let me know!

M@
Oct 5 '07 #11
gcoaster
117 100+
NeoPal, thank you! every little bit counts..

one comment, that is some SERIOUS VBA!!!!

being the newbie I am, I was getting errors with what i copied and pasted from FishVAl and at 2am in the morning i was just ready to just use a WAMP in a VMWARE machine and switch over to MySQL using MyPhpAdmin and php w/ XTHML + CSS with a pretty web2.0 interface and maybe some spry.. using dreamweaver and Adobe Dreamweaver Developer Toolbox,

( yea that sounds complex but i am finding the comboboxes in access hurt my brain more! HAHA )

I CANNOT imagine debugging the fallowing until i learn the basics.
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub txtFindAccountCode_AfterUpdate()
  5.     Call CheckFilter
  6. End Sub
  7.  
  8. Private Sub txtFindCreationDate_AfterUpdate()
  9.     Me!txtFindCreationDate = IIf(IsDate(Me!txtFindCreationDate), _
  10.                                  Format(Me!txtFindCreationDate, "d mmm yyyy"), _
  11.                                  "")
  12.     Call CheckFilter
  13. End Sub
  14.  
  15. Private Sub cboFindAccountType_AfterUpdate()
  16.     Call CheckFilter
  17. End Sub
  18.  
  19. 'CheckFilter produces the new Filter depending on the values currently in
  20. 'txtFindAccountCode, txtFindCreationDate & cboFindAccountType.
  21. Private Sub CheckFilter()
  22.     Dim strFilter As String, strOldFilter As String
  23.  
  24.     strOldFilter = Me.Filter
  25.     'txtFindAccountCode - Text
  26.     If Me!txtFindAccountCode > "" Then _
  27.         strFilter = strFilter & _
  28.                     " AND ([AccountCode] Like '" & _
  29.                     Me!txtFindAccountCode & "*')"
  30.     'txtFindCreationDate - Date
  31.     If Me!txtFindCreationDate > "" Then _
  32.         strFilter = strFilter & _
  33.                     " AND ([CreationDate]=" & _
  34.                     Format(CDate(Me!txtFindCreationDate), _
  35.                            "\#m/d/yyyy\#") & ")"
  36.     'cboFindAccountType - Numeric
  37.     If Me!cboFindAccountType > "" Then _
  38.         strFilter = strFilter & _
  39.                     " AND ([AccountType]=" & _
  40.                     Me!cboFindAccountType & ")"
  41.     'Debug.Print ".Filter = '" & strOldFilter & "' - ";
  42.     'Debug.Print "strFilter = '" & strFilter & " '"
  43.     'Tidy up results and apply IF NECESSARY
  44.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  45.     If strFilter <> strOldFilter Then
  46.         Me.Filter = strFilter
  47.         Me.FilterOn = (strFilter > "")
  48.     End If
  49. End Sub
Oct 5 '07 #12
NeoPa
32,556 Expert Mod 16PB
Gold,

I suggest you put your actual project aside for a bit while you progress through this article. It's a bit like a tutorial and includes the database to download.
If you have trouble with it or specific questions, I can help. I expect once you start to go through it it will start to make better sense.
Oct 5 '07 #13
gcoaster
117 100+
Hello NeoPa,
thank you for offering to help. You are a scholar and a gentleman

It doesn't look that bad, I just may read and study.. just noticed like in CSS the
lines that start with a ' is a comment */ comment */ so there is not as much code as i thought.
One thing, It is 2007, things are going FAST.. guys like me DONT HAVE TIME, especially trying to debug code and it ends up being a comment out of place. then you have to search for help on the obscure ms error message.

Trying to stay ahead of the game is almost information overload, you miss a beat and your behind, I have learned to KEEP IT SIMPLE
you get IN and you get OUT.

I could and actually will spend another 2 days figuring this out, then I get it done.. enter data and don't dive into the code again till i want to customize it or something isn't right..

this is one reason allot of people use FileMaker, they get frustrated with access and filemaker you get in and get out. but once your in your in!

by the way, i did have my doubts with going with access 07, there is not a access 2007 export to MySQL yet, but you can always make table etc etc.

anyways, thank you all!

Matt
Oct 5 '07 #14
gcoaster
117 100+
Hello FishVal,

I need your help please, I think I am close.
I keep getting an error.. here is the code
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub cmboMainCategory_AfterUpdate()
  4.     With Me!cmboSubCategory
  5.         If IsNull(Me!cmboMainCategory) Then
  6.             .RowSource = ""
  7.         Else
  8.             .RowSource = "SELECT keyCategoryID,txtCategoryName" & _
  9.                  "FROM @CATEGORY" & _
  10.                  "WHERE keyParentCategory=" & Me!cmboMainCategory & ";"
  11.             End If
  12.             Call .Requery
  13.     End With
  14. End Sub
-- what am i doing wrong?! thank you
Oct 6 '07 #15
FishVal
2,653 Expert 2GB
Hello FishVal,

I need your help please, I think I am close.
I keep getting an error.. here is the code

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub cmboMainCategory_AfterUpdate()
  4.     With Me!cmboSubCategory
  5.         If IsNull(Me!cmboMainCategory) Then
  6.             .RowSource = ""
  7.         Else
  8.             .RowSource = "SELECT keyCategoryID,txtCategoryName" & _
  9.                  "FROM @CATEGORY" & _
  10.                  "WHERE keyParentCategory=" & Me!cmboMainCategory & ";"
  11.             End If
  12.             Call .Requery
  13.     End With
  14. End Sub
  15.  
-- what am i doing wrong?! thank you
Hi, Matt.

The code seems to be Ok.
  • what error are you getting? where code execution stops?
  • what are the settings of [cmboMainCategory] and [cmboSubCategory] properties ?
    • ColumnCount
    • BoundColumn
    • RowSource
  • did you try to execute RowSource statement in query builder?
Oct 6 '07 #16
gcoaster
117 100+
Hello FishVal

Here is what I have

Table
@CATEGORY

Columns in @CATEGORY Table
mainCategoryID
name
keyCategoryID

Combo Boxes
cmboMainCategory
cmboSubCategory

Expand|Select|Wrap|Line Numbers
  1. Properties of Combo Boxes
  2.     cmboSubCategory
  3.         Control Source       | softCategory ( tried nothing as well )
  4.         Row Source            | @CATEGORY
  5.         Bound Column       | tried everything 1 2 3 
  6.         Count                       | 2
  7.         Widths                     | 0cm;1cm 
  8.  
  9.     cmboSubCategory
  10.         Control Source       | softSubCategory ( tried nothing as well )
  11.         Row Source            | @CATEGORY
  12.         Bound Column       | tried everything 1 2 3 
  13.         Count                       | 2
  14.         Widths                     | 0cm;1cm
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmboMainCategory_AfterUpdate()
  2.     With Me![cmboSubCategory]
  3.         If IsNull(Me!cmboCategory) Then
  4.             .RowSource = ""
  5.         Else
  6.            .RowSource = "SELECT MaincategoryID, name" & _
  7.                         "FROM @CATEGORY " & _
  8.                         "WHERE [keyCategoryID]=" & Me!cmboMainCategory
  9.         End If
  10.         Call .Requery
  11.     End With
  12. End Sub
Matts hair… -handfull per 2 errors and no results

Question: If I ever get this working.. then how do I add the next 2?
Type and then Sub Type?
thank you FishVal
Oct 6 '07 #17
FishVal
2,653 Expert 2GB
Hi, Matt.

See the attached example.
Attached Files
File Type: zip 4CascadeCombos.zip (13.3 KB, 290 views)
Oct 6 '07 #18
NeoPa
32,556 Expert Mod 16PB
Hello FishVal,

I need your help please, I think I am close.
I keep getting an error.. here is the code
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Sub cmboMainCategory_AfterUpdate()
  4.     With Me!cmboSubCategory
  5.         If IsNull(Me!cmboMainCategory) Then
  6.             .RowSource = ""
  7.         Else
  8.             .RowSource = "SELECT keyCategoryID,txtCategoryName" & _
  9.                  "FROM @CATEGORY" & _
  10.                  "WHERE keyParentCategory=" & Me!cmboMainCategory & ";"
  11.             End If
  12.             Call .Requery
  13.     End With
  14. End Sub
-- what am i doing wrong?! thank you
No space before the FROM (or the WHERE for that matter).

@Gold Please notice that two of your posts now have the edit comment (Please use [code] tags).
This is because everything works so much better when you can read what's being posted. I'm sure Fish would have seen the missing space if it had been laid out clearly.

*edit* I just noticed a later post indicating you're obviously trying. Look at the (#) button when creating or editing your post and read the text at the right on the "New Post" page for hints :)
Oct 6 '07 #19
NeoPa
32,556 Expert Mod 16PB
If you examine the .RowSource property after it's been set up - you'll easily see what I mean ;)
Oct 6 '07 #20
gcoaster
117 100+
Hi, Matt.

See the attached example.
Thank you FishVal

the database you uploaded, DOES NOT have any vba..
After update just has a =RequireDescCombo(2) are you recommending not using a module?

and if this is in a form.. can the Control Source be appended to a column in a table?
Oct 7 '07 #21
gcoaster
117 100+
Hello NeoPa,
ROW SOURCE = "nothing"


If you examine the .RowSource property after it's been set up - you'll easily see what I mean ;)
Oct 7 '07 #22
gcoaster
117 100+
FishVal, NeoPa..

I got it to work, HOW EVER..

when the data is selected and posted to control source/table

Numbers are entered, instead of text!

LEVEL1 LEVE2 LEVEL3 LEVEL4
1 2 3 4

How do I get it to show, or post as, or enter as text?

LEVEL1 LEVE2 LEVEL3 LEVEL4
Software Micro$0ft Access 2003 PAIN IN THE

ALMOST!
Oct 7 '07 #23
NeoPa
32,556 Expert Mod 16PB
Hello NeoPa,
ROW SOURCE = "nothing"
Looking at your code from post #17.
Let line #6 run (so Me!cmboCategory NOT null) then look at the contents of the .RowSource control.
Oct 7 '07 #24
gcoaster
117 100+
Looking at your code from post #17.
Let line #6 run (so Me!cmboCategory NOT null) then look at the contents of the .RowSource control.
So Line 6
Expand|Select|Wrap|Line Numbers
  1.    .RowSource = "SELECT MaincategoryID, name" & _
Should Now Be
Expand|Select|Wrap|Line Numbers
  1.            .RowSource = "SELECT MaincategoryID, name" & _ so Me!cmboCategory NOT null
  2.  
?!?!?
Oct 7 '07 #25
NeoPa
32,556 Expert Mod 16PB
So Line 6
Expand|Select|Wrap|Line Numbers
  1. .RowSource = "SELECT MaincategoryID, name" & _
Should Now Be
Expand|Select|Wrap|Line Numbers
  1. .RowSource = "SELECT MaincategoryID, name" & _ so Me!cmboCategory NOT null
?!?!?
No. Not at all.
Add the following line into your code after line #8 (Lines #6 to #8 are actually all the same line in VBA)
Expand|Select|Wrap|Line Numbers
  1. Call MsgBox(.RowSource)
Then look at the SQL as it's shown to see clearly why your code is not quite right (Again Let line #6 run (so Me!cmboCategory NOT null)).
Oct 7 '07 #26
gcoaster
117 100+
NeoPa, I am Almost there.

All I need now is to figure out how to get DLookUp to write to a field!
Expand|Select|Wrap|Line Numbers
  1. =DLookUp("[model]","qPRODrest")
  2. =DLookUp("[make]","qPRODrest")
  3. =DLookUp("[description]","qPRODrest")
  4. =DLookUp("[UnitPrice]","qPRODrest")
  5. =DLookUp("[purchasedPrice]","qPRODrest")
Last Step I used DLookUp to bring the data in to last leftover fields from cascade comboboxes...

I ended up using one table and 4 querys.
A little VBA as well!
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo0_AfterUpdate()
  2. Me!Combo1.Requery
  3. End Sub
  4.  
  5. Private Sub Combo1_AfterUpdate()
  6. Me!Combo2.Requery
  7. End Sub
each combobox, category/subCategory/type.. used each query!
the query's filter each other
for instance, in the subcategory query

Category | PRODUCT | Groupby |
[Forms]![INVOICE]![INVOICEsubform]![ComboCategory]

The Last query pulls in the rest and populates the left over fields, Text Boxes bound to table fields in details table..

the values are there! its working! but the values are NOT writing to the text box's!!! to the table columns!!!

I realized it when I couldn't get the grandtotal to add up! oh man! I have been working 1 week on this, micro$oft is killing me.

one last step and I am stuck!!! ahahaha i HATE ACCESS!! LOL
Attached Images
 
Attached Images
File Type: jpg screenShot.jpg (22.3 KB, 477 views)
File Type: jpg form.jpg (8.3 KB, 250 views)
Oct 8 '07 #27
NeoPa
32,556 Expert Mod 16PB
Please check out post #19 where it talks about using [ CODE ] tags in your posts. I've had to edit your post again and frankly I'm getting tired with tidying up after you.

Also, if you'd like me to continue working with me I'd appreciate feedback related to my posts. Explaining where you are from scratch (as you seem to have in your last post) is frustratingly difficult to follow.

How would you communicate with someone when they appear to ignore everything you try to tell them and just go on their own merry way regardless. It's not good manners and it's very difficult for me to be of any use to you.

I still don't know if you've understood my first point yet and, regardless of whether you work by jumping around from issue to issue, I know better, so don't expect me to follow you.
Oct 8 '07 #28
gcoaster
117 100+
Expand|Select|Wrap|Line Numbers
  1. Ok, I am with you. I will start using the code tag with the editor
Oct 8 '07 #29
gcoaster
117 100+
OK! I think I got it! (including putting the code in the code tags for neopa) I think I got comboboxes to filter using querys to last combobox then last combobox populates the remaining columns in table!
you have taught me well FishVal.

this solution uses hardly ANY vba and writes TEXT to record instead of ID number.

The fallowing comboboxes are cascading comboboxes and filter to comboprodname. using 5 querys.

Expand|Select|Wrap|Line Numbers
  1. Combocategory
  2. Combosubcategory
  3. Combotype
  4. comboboxsubtype
  5. Comboprodname
When item is selected in comboprodname combobox..
Then the remaining fields in table (which are each bound in control source)
are populated VIA vba!

The remaining text box fields on form are

Expand|Select|Wrap|Line Numbers
  1. Description
  2. Make
  3. Model
  4. UnitPrice
  5. purchasedPrice
So VBA in afterupdate in Comboprodnamewhich is the
LAST combobox should look something like this?

Expand|Select|Wrap|Line Numbers
  1. Private Sub productName_AfterUpdate()
  2. Me.description = DLookup("[description]", "qPRODrest")
  3. Me.make = DLookup("[make]", "qPRODrest")
  4. Me.model = DLookup("[model]", "qPRODrest")
  5. Me.UnitPrice = DLookup("[UnitPrice]", "qPRODrest")
  6. Me.purchasedPrice = DLookup("[purchasedPrice]", "qPRODrest")
  7. End Sub
wait, something is out of the ordinary.. it works!

I will post the entire project and code with comprehensible images when I am done with this here if I can and on my website,

Freely ye have received, freely give. Matt 10:8

thank you FishVal!

And NeoPa.

Matt
Oct 8 '07 #30
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. Ok, I am with you. I will start using the code tag with the editor
Gold,

I think I needed to say what I had to say, but I'm pleased to see that it hasn't curbed your enthusiasm.
I'm very pleased that you managed to resolve your issues (mainly with FishVal's help - He's good that chap). I was also pleased that your explanation (which is always appreciated from posters after a successful resolution) was expressed clearly and was easy to read and understand.

Please come back and post if you have further issues :)

-NeoPa.
Oct 9 '07 #31
FishVal
2,653 Expert 2GB
Hi, Matt.

Glad you've got it work.
Hope you had a time struggling with your code hard enough to really enjoy the moment when it got work. ;)

Best regards,
Valentine
Oct 9 '07 #32
gcoaster
117 100+
Valentine
yes you are my Valentine! ;-)

Hello FishVal
and
Expand|Select|Wrap|Line Numbers
  1. NeoPa, 
you guys are great..

I got one more for you before i experience even more JOY! ( oh and there was joy when It all worked, when i closed one eye and clicked and held my breath and it worked i woke the neighbors)

Also, I understand VBA now thanks to you guys. i remember picking up the ACCESS 2007 books and seeing the VBA code i would stop and say "give me a break" I actually go back now and open the same books and understand it now! what a TRIP.

Comboxes are working great.. when I add products. and as a new database, I am finding errors and renaming categories. is there a bit of code
that I can add to the VBA that will clear the boxes AFTER?
EXAMPLE
HARDWARE | CPU | AMD | AM2 | CHEAP
lets say I want to change AMD to INTEL
when I go back and change HARDWARE in first combobox, it dynamically clears all of the fallowing combboxes?

Expand|Select|Wrap|Line Numbers
  1. [cboSubCat] [cboType] [cboSubType]
HARDWARE | nothing | nothing | nothing |
Also, I am not using the Querys anymore! only for the first combobox.
[cboCat]
here is the code I am using now

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCat_AfterUpdate()
  2.    With Me![cboSubCat]
  3.         If IsNull(Me!cboCat) Then
  4.         .RowSource = ""
  5.         Else
  6.         .RowSource = "SELECT DISTINCT subCategory " & _
  7.                 "FROM PRODUCT " & _
  8.                 "WHERE PRODUCT.category= '" & Me!cboCat & "' " & _
  9.                 "ORDER BY PRODUCT.subCategory;"
  10.         End If
  11.         Call .Requery
  12.     End With
  13. End Sub
  14. Private Sub cboproductName_AfterUpdate()
  15. Me!description = DLookup("[description]", "qPRODrest")
  16. Me!make = DLookup("[make]", "qPRODrest")
  17. Me!model = DLookup("[model]", "qPRODrest")
  18. Me!UnitPrice = DLookup("[UnitPrice]", "qPRODrest")
  19. Me!purchasedPrice = DLookup("[purchasedPrice]", "qPRODrest")
  20. End Sub
  21.  
  22.  
  23. Private Sub cboSubCat_AfterUpdate()
  24.    With Me![cboType]
  25.         If IsNull(Me!cboSubCat) Then
  26.         .RowSource = ""
  27.         Else
  28.         .RowSource = "SELECT DISTINCT type " & _
  29.                 "FROM PRODUCT " & _
  30.                 "WHERE PRODUCT.subCategory= '" & Me!cboSubCat & "' " & _
  31.                 "ORDER BY PRODUCT.type;"
  32.         End If
  33.     Call .Requery
  34.     End With
  35. End Sub
  36. Private Sub cboType_AfterUpdate()
  37.    With Me![cboSubType]
  38.         If IsNull(Me!cboType) Then
  39.         .RowSource = ""
  40.         Else
  41.         .RowSource = "SELECT DISTINCT subType " & _
  42.                 "FROM PRODUCT " & _
  43.                 "WHERE PRODUCT.type= '" & Me!cboType & "' " & _
  44.                 "ORDER BY PRODUCT.subType;"
  45.         End If
  46.     Call .Requery
  47.     End With
  48. End Sub
  49. Private Sub cboSubType_AfterUpdate()
  50.    With Me![cboproductName]
  51.         If IsNull(Me!cboSubType) Then
  52.         .RowSource = ""
  53.         Else
  54.         .RowSource = "SELECT productName " & _
  55.                 "FROM PRODUCT " & _
  56.                 "WHERE PRODUCT.subType= '" & Me!cboSubType & "' " & _
  57.                 "ORDER BY PRODUCT.productName;"
  58.         End If
  59.     Call .Requery
  60.     End With
  61. End Sub
When [productName] is selected, THEN it runs a QUERY that looks up the rest of the values filted from QUERY

VBA in [productName]

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboproductName_AfterUpdate()
  2. Me!description = DLookup("[description]", "qPRODrest")
  3. Me!make = DLookup("[make]", "qPRODrest")
  4. Me!model = DLookup("[model]", "qPRODrest")
  5. Me!UnitPrice = DLookup("[UnitPrice]", "qPRODrest")
  6. Me!purchasedPrice = DLookup("[purchasedPrice]", "qPRODrest")
  7. End Sub
and here is filter in the QUERY criteria for productName

Expand|Select|Wrap|Line Numbers
  1. [Forms]![INVOICE]![INVOICEsubform]![cboproductName]


Thank you many many times over! I got more brat time with my 2 sons!

M@
Attached Images
File Type: jpg mattsQuery.jpg (7.5 KB, 364 views)
Oct 10 '07 #33
NeoPa
32,556 Expert Mod 16PB
Well Gold, It's certainly fun when you get something working and I'm glad you've had that satisfaction (and especially the extra time with your kids).
As to your combobox behaviour, every time you select an item from any of the comboboxes it will start the others (lower down the tree) again from scratch. As you can see this will happen both when the field is redone (.RowSource reset) and when a new item is selected.
Expand|Select|Wrap|Line Numbers
  1. -NeoPa.
Oct 11 '07 #34
FishVal
2,653 Expert 2GB
Data organized in a way discussed in this thread could be advantageously represented in TreeView control. See Nested Display thread.
Apr 20 '09 #35

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Travis Pupkin | last post by:
Hey, I've done a number of product catalogs/galleries with one or two category levels (Category > Subcategory). The straightforward way to do this, of course, is to use database fields for...
3
by: Rich Protzel | last post by:
Hello, So my table contains say 100,000 records, and I need to group the categories in fld1 by the highest count of subcategories. Say fld1 contains categories A, B, C, D, E. All of these...
1
by: A.J.M. van Rijthoven | last post by:
I have a form with data from a box (Table box), on his form is a subform with the instuments that are in this box. The instruments (Table instruments) are categorized by category (Table Category)....
9
by: Neil Ginsberg | last post by:
I have a strange situation using Access to automate a Word mail merge. Using Access 2000 and Word 2000, the code opens Word, opens the document in Word, sets a table in the calling Access...
0
by: Ron | last post by:
I am trying to create a nested DataList with multiple subcategories listed under each primary category. Unfortunately, I end up with a bunch of multiple SubCategory values after iterating through...
1
by: bobika | last post by:
Hi Im am implementing a small database system using MS Access. I have two main fields: :product category and product type! Product category contains ABC and XYZ categories. I added both in the...
1
by: Webstorm | last post by:
Hi, I hope someone can help me sort this out a bit, Im completely lost. Here is the page I am working on: http://www.knzbusinessbrokers.com/default.asp I have 3 search critera that I need to...
1
by: Brit | last post by:
I have an ASP file that retrieves names from an Access database for 4 different categories of membership, which the visitor to the page selects (corporate, institutional, regular, or student). The...
3
by: jillinsky | last post by:
Wondering is this is possible - I have 2 tables. One is categories, and has catid, catname, hashighercat, and ...I can't think of the 4th one, but it isn't needed anyway. There are 40...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.