|
Question : Dropdown list with Category & subcategories out of the same table
|
|
Hey,
I'm quite new to access, so this might be a stupid question, or just impossible.
But here I go: I have a table with categories that looks like: -catid -parentcatid -name
Parentcatid is also a catid and the current category is a subcategory of the parent category. That way i can have unlimited subcategories.
However i want to have a dropdown list on a form with all categories, and the more a category is nested, the more it is indented.
So like:
Category subcategory subsubcategory subsubcategory subsubsubcategory category subcategory ...
A bit like the 'forum jump' select menu on this forum.
Any idea how to do this?
Thanks in advance,
|
|
Answer : Dropdown list with Category & subcategories out of the same table
|
|
Here's an example of processing a recordset:
dim rst as recordset dim sql as string 'construct your SQL here if level = 0 sql = '??????' else sql = '??????' end if
Set rst = currentdb().OpenRecordset(sql, dbOpenDynaset, dbReadOnly) Do Until rst.EOF call RecursiveProcedure(level+1, rst.catid) rst.MoveNext Loop rst.close
To clear the rowsource YourComboBox.RowSource = NULL
To concatenate to the rowsource.
YourComboBox.RowSource = nz(YourComboBox.RowSource & ";",YourComboBox.RowSource) & rst.CategoryName
|
|
|
|