I have a simple form in an Access 2007 database. The form contains two combo boxes. Combo box 1 contains the names of all the base and linked tables in the database.
When the user selects a table name in combo box 1, I want combo box 2 show the list of fields for that table.
The code I have to populate combo box 2 with field names looks like this:
Expand|Select|Wrap|Line Numbers
- Private Sub Combo_Box_1_Change()
- Dim FLD As String
- Dim INDEXtdef As DAO.TableDef
- Dim VarItm As Variant
- 'Initiate the FLD string variable
- FLD = ""
- Set INDEXtdef = CurrentDb.TableDefs(Combo_Box_1.Value)
- For Each VarItm In INDEXtdef.Fields
- 'Build the string variable
- FLD = FLD & VarItm.Name & "; "
- Next
- 'Trim off the extra semi-colon and space
- FLD = Left(FLD, Len(FLD) - 2)
- Combo_Box_2.RowSource = FLD
- End Sub
Expand|Select|Wrap|Line Numbers
- For Each VarItm In INDEXtdef.Fields
Thanks,
sphinney