Yes, the question of the data structure is the more significant one.
To get these combos to work correctly, you need to make the *text* the
primary key:
Table1:
Attribute = Text and primary key
SortOrder = Number (lower numbers sort first).
Table2:
SubAttribute = Text and primary key
Attribute = Text, and foreign key to Table1.Attribute.
SortOrder = Number (lower numbers sort first).
In your form, you will have two combos:
- Combo1 with a RowSource of:
SELECT Attribute FROM Table1 ORDER BY SortOrder, Attribute;
- Combo2 with an initial RowSource that gives no records:
SELECT SubAttribute FROM Table2 WHERE (False);
In the Enter event of the 2nd combo, change it's RowSource like this:
Me.Combo2.RowSource = "SELECT SubAttribute FROM Table2 WHERE Attribute =
""" & Me.Combo1 & """ ORDER BY SortOrder, SubAttribute;"
The reason you can't use the AutoNumber is that there is not a separate
recordset for the rowsource of every combo on every row of the continuous
subform. Since there is only one RowSource and it is restricted to value
that match Combo1 in the current record only, the combo will go blank in all
the other rows of the subform if its bound column is zero-width. This
doesn't happen if the text is the primary key, because Access can just show
that value. And as soon as you move to another row to drop the list down,
Combo2's Enter event fires, so the RowSource is re-evaluated, so by the time
the combo drops down the list is populated with the correct values.
That works. It does not address the issue that you are storing redundant
data, i.e. the valules for both Combo1 and Combo2, when the value of Combo2
actually does define the value of Combo1 as well. Strictly, that's not
correctly normalized, but you may want to do it anyway.