I figured it out chewey, with help from a few. Here's a slow step-by-step on how it's done...
==========================
Dynamic Comboboxes Tutorial - Alpha release 0.0.3 - Feb 7 2003
==============================================================
This tutorial is an attempt to familiarise myself with creating dynamic comboboxes in Microsoft Access. This is where a set of comboboxes change according to what is selected. For example, if the first combobox contains, "animal", "vegetable" and "computer", the second combo box will have choices of "cat", "dog" and "rodent" when "animal" is selected from the first. Otherwise, if "vegetable" is selected from the first combobox, the second will change its contents to "fruit", "herb" and "spice".
Contents - This tutorial is in the form of...
readme 0x0x3.txt (this document)
dynacombo.mdb (example database in Access 2000 format)
dyncom97.mdb (the same database converted to Access 97 format)
==GPL==GPL==GPL==GPL==GPL==GPL==GPL==GPL==
Licence / Terms for using this Document
=======================================
This tutorial is released under GNU Public Licence (GPL). This means you can copy it, change bits you don't like, add to it and give it out to all your friends. You can even make money by charging a fee while using the information in this document as a teaching aid. However, under GPL, if anyone requests that you give them a copy of this document free of charge, you must comply. Likewise, any modifications you make working from this information must also be available free of charge. You may agree to sell information in this document, or for modifiactions you have made for a profit, as long as you make it clear that the information will be offered for free and without restriction or hesitation, should other parties request it.
This licence must remian part of the document and also included on projects using this information in their own making.
==GPL==GPL==GPL==GPL==GPL==GPL==GPL==GPL==
On with the tutorial...
First up, we need some information to go into the database. Let's work from the following...
<Root>
|
|__animal
| . |
| . |__cat
| . | . |_tiger
| . | . |_lion
| . | . |_panther
| . |
| . |__dog
| . | . |_wolf
| . | . |_alsation
| . | . |_doberman
| . |
| . |__rodent
| . . . |_rat
| . . . |_mouse
| . . . |_rabbit
|
|__vegetable
| . |
| . |__fruit
| . | . |_banana
| . | . |_orange
| . | . |_apple
| . |
| . |__herb
| . | . |_thyme
| . | . |_parsley
| . | . |_basil
| . |
| . |__spice
| . . . |_curry
| . . . |_tumeric
| . . . |_cinnamon
|
|__computer
. . |
. . |__operating system
. . | . |_linux
. . | . |_win32
. . | . |_mac-os
. . |
. . |__application
. . | . |_word processor
. . | . |_spreadsheet
. . | . |_database
. . |
. . |__hardware
. . . . |_scanner
. . . . |_monitor
. . . . |_floppy
The above are to be categorised as "category" => "group" => "item"
CREATING THE INITIAL DATABASE
=============================
There are several ways to do this. You could just enter the data as raw tables, or you could make nice tidy data entry forms. The second option is the best because those forms, while cumbersome to make at first, are useful for later updates, and there's less likelyhood of dataentry error when unit-ID's are autonumbered directly from the forms.
Start a new database, save as "dynacombo.mdb"
CREATING TABLES:
================
Make New Table in Design View. Give two fields...
categoryID (AutoNumber) as Primary Key
categoryName (Text)
...on closing, save table as "category"
Likewise, make two more tables saved as "group" and "item"
Table: group
groupID (AutoNumber) as Primary Key
catID (Number)
groupName (Text)
Table: item
itemID (AutoNumber) as Primary Key
grpID (Number)
itemName (Text)
Relationships ==========================
Once all tables are closed & saved, hit the relationships button. add all three tables to the view, and link...
* categoryID to catID (choose to enforce referential integrity)
* groupID to grpID (choose to enforce referential integrity)
Close the relationships section, opting to save layout changes when prompted.
========================================
Finally make one more table in design view. Give it four fields...
* choiceID (AutoNumber) - Primary key
* chosencat (Number)
* chosengrp (Number)
* chosenitm (Number)
Save the table as "choices". This is where all the records are going to be stored during data entry.
CREATING DATA ENTRY FORMS
=========================
For some bizarre reason, my autoform wizards only work about 25% of the time, even though I'm on a 1.2Ghz machine, a clean install of Win98-SE and only a few apps installed (nothing heavy... I haven't even set up the internet). Oh well - manual construction of forms works pretty well every time, so here I go...
Category dataentry form:
Create new form in design view. Base it on the "category" table. Slide the "categoryName" fields onto the canvas as a text box. You do not need the "categoryID" field. When closing, save the table as "newcategory"
Group dataentry form:
Create a new form in Design View based on group. From the drag'n'drop field window, you only need to add the field "Group Name". You will also need an option to choose which category the new group is under (when you do create the new group "dog", you will need to specify that it belons to the category "animal"). It is neater to create a pull down list than having a text box (which is why you haven't added the field from the drag'n'drop field window... this would have given you a plain textbox).
From the toolbox, add a new combobox (again, I normally have the wizard button down, but *sigh* I guess I'll have to do this one manually as well)
Control Source => CatID
Make sure "Row Source Type" is down as Table/Query. Under "Row Source", hit the three dots and add the category table to the SQL Statement view. Have "CategoryID" and "categoryName" as two columns. If done correctly, "SELECT category.categoryID, category.categoryName FROM category; " should now bw written into the "Row Source" field.
Make the following changes to change the combobox (pulldown list) to a more friendly format than displaying raw ID numbers...
* Set Column Count to 2
* Set Column Widths to 0";1"
Rename the field lable from "Combo1:" to "Category:"
Optional: because you've added the combobox after the initial textbox, go the tab order is altered, so hitting the ENTER key after making a new field will refocus onto the pulldown list. Change the TabIndex of the groupName textbox from 0 to 1
On closing, save the form as "newgroup"
Item dataentry form:
Create new form in Design view, based on the "item" table.
Slide on the item field (as textbox) from the field list window.
Add new combobox from toolbox window. Select grpID as its Control Source.
Make sure "Control SourceType" for the combobox is set to Table/Query and hit the three dots at the end of "Row Source". In the SQL Statement view, add the "group" table. Next add "groupID" and "GroupName" as columns for the SQL Statement. This will result in "SELECT group.groupID, group.groupName FROM [group];" being written into the "Row Source" property for the combo box.
To make the combobox have userfriendly pulldown list items...
* Set Column Count to 2
* Set Column Widths to 0";1"
Optional: change the Tab Index of the itemName textbox from 0 to 1
On exit, save the form as "newitem"
ENTERING THE DATA INTO THE TABLES
=================================
Open the newcategory form in Form View, ready for data entry. Enter each of "animal", "vegetable" and "computer" before closing the form.
Open the newgroup form in Form View.
selecting "animal" from the pull down list each time, enter records for "cat", "dog" and "rodent"
Do the same for...
pulldown: vegetable => "fruit", "herb" and "spice"
pulldown: computer => "operating system", "application" and "hardware"
Open the newitem form in Form View
Under "cat" (combobox pull down list) add entries for "tiger", "lion" and "panther"
Enter other data as in tree diagram at the beginning of this tutorial.
Okay - that's all I have room for in a single post to this forum.
(More to come...)