How to make a dropdown list with (sub) categories

waza

New member
Local time
Today, 09:14
Joined
Mar 5, 2008
Messages
4
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,
Waza
 
Last edited:
Well, i searched a lot and this is what I currently have:

I have a combobox named 'categorie'

and a table categorie, with fields: catid, parentid, naam

And this piece of code:

Code:
Option Compare Database
Sub AddChildren(catid As Integer, rst As DAO.Recordset, level As Integer)
    Dim StrText As String, bkMark As String, i As Integer, d As Integer
    rst.FindFirst "[parentid] ='" & catid & "'"
    
    Do Until rst.NoMatch
        Dim d As Integer
        StrText = ""
        For d = 0 To level
            StrText = StrText & " "
        Next d
        StrText = StrText & rst![naam]
        categorie.RowSource = Nz(categorie.RowSource & ";", categorie.RowSource) & StrText
        bkMark = rst.Bookmark
        i = i + 1
        level = level + 1
        AddChildren rst.catid, rst, level        'CALLING ITSELF
        rst.Bookmark = bkMark
        rst.FindNext "[parentid] ='" & catid & "'"
    Loop

End Sub

Private Sub Form_Load()
    Dim db As Database, rst As Recordset
    Dim StrText As String, bkMark As String, FoldType As Integer
 
    Set db = CurrentDb
    Set rst = db.OpenRecordset("SELECT catid,parentid,naam FROM categorie ORDER BY parentid ASC", dbOpenDynaset, dbReadOnly)

    categorie.RowSource = Null
    AddChildren 0, rst, 0

    rst.Close
    Set db = Nothing
End Sub

But it doesn't work :(


Can somebody say what I do wrong (i'm really a very beginner with access)
Thanks,
 

Users who are viewing this thread

Back
Top Bottom