List Fields from a table?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone have a function or suggestions on how to display a list of fields
in a table in a combo box?
I have a form that allows a user to select a table from a list of tables in
the db, but I can't get my function to list the fields in that table in a
separate combo box.

I got my "ListAllTables" function from the microsoft website and now am
trying to 'convert' it to do the same for listing the fields.

Thanks.
 
Brian said:
Does anyone have a function or suggestions on how to display a list of fields
in a table in a combo box?
I have a form that allows a user to select a table from a list of tables in
the db, but I can't get my function to list the fields in that table in a
separate combo box.

I got my "ListAllTables" function from the microsoft website and now am
trying to 'convert' it to do the same for listing the fields.

A ComboBox has three choices for RowSourceType and one of them is
FieldList. Just choose that and put the name of the table in the RowSource
property.
 
This might be easier than you may think.
One of the three options on a combo box Rource Source Type is "Field List."
This will list all the fields in whatever table is put on the Row Source property.

A quick test using these steps worked just fine.
1. Assume table combo is called cboTables and field combo is cboFields.
2. Set the Row Source Type of cboFields to "Field List".
3. Set the Row Source property of cboFields to nothing (blank).
4. Code the AfterUpdate event of cboTables to this:

Private Sub cboTables_AfterUpdate()
Me.cboFields = Null
Me.cboFields.RowSource = Me.cboTables
Me.cboFields.SetFocus
End Sub

Selecting a table from the first combo reveals a list of relevant fields in the second combo box.
 
Back
Top