Cascading Combo Boxes for Table and Field Names

Jallie

New member
Local time
Today, 04:09
Joined
Mar 13, 2013
Messages
5
[SOLVED] Cascading Combo Boxes for Table and Field Names

Hello,

Currently, I have a form with a combobox that lists all of the names of the tables inside my database. Depending on the table selected in the first combobox, I would like to have another combobox which allows the user to choose from the field names inside that table.

Is this possible? I am pretty new to Access, so any help is much appreciated.
Thank you.
 
Last edited:
If you already have the table names in the bound column of your first combo box, and assuming that the Row Source Type of the second combo box was set to Value List, then you could use code like the following in the After Update event of the first combo box. In the following example you need to modify each instance of Combo1 and Combo2 to the actual names of your combo boxes;

Code:
Private Sub Combo1_AfterUpdate()
    
    Dim db As Database
    Dim td As TableDef
    Dim i As Integer
    Dim strList As String
    
    Set db = CurrentDb
    Set td = db.TableDefs(Me!Combo1)
    
    For i = 0 To td.Fields.Count - 1
        strList = strList & td.Fields(i).Name & ";"
    Next i
    
    'Remove the trailing ;
    strList = Left(strList, Len(strList) - 1)
    
    Me!Combo2.RowSource = strList
    
End Sub
 
Hello Sean,

You're awesome. That's perfect and exactly what I was looking for. Thank you so much for your time! I really appreciate your reply.
 

Users who are viewing this thread

Back
Top Bottom