field names

  • Thread starter Thread starter Terry
  • Start date Start date
T

Terry

How do I reference the field names of a table or query to be used as the
rowsource of a cbobox?
 
Can't recall needing to do this, but you could examine the Fields collection
of the TableDef or QueryDef.

Alternatively, you could OpenRecordset using whatever is in the combo's
RowSource (table name, query name, or SQL statement), and examine the Fields
collection to find the Name of each.
 
Not sure what you are asking but

if you want to use a table or query as the recordsource for your combobox
just use the wizard and it will do it all for you.
Suppose your query returns two columns of data - UniqueField and
Description - If you want to only display the Description field but want to
store the UniqueField for future use then make sure that in the Properties
of the combobox the following are set:

FORMAT
Column Count = 2
Column Widths = 0;1cm (or something big enough to show description)

DATA
Bound Column = 1

HTH
 
Try using the Wizard. The "Combo Box Wizard" will take
you through all of the necessary steps to create the Combo
Box.

To display the Wizard, open a Form in "Design View", on
the Menu Bar, click "View/Toolbar". There is a button on
the displayed Toolbar that looks like a magic Wand, ensure
this button is "De-pressed" to run the Wizard. Hover the
Mouse over the displayed Toolbar Commands, you are looking
out for "Combo Box".

HTH.

Tony C.
 
I'm developing a setup form that matches fields from two different db and I
need to have a combobox that the user will select the right, contact method
in this case, to a field in another db.

I just haven't figured out how to get at the table field names as a
recordset yet.

I was thinking something along: combo.rowsource =
querydef("qryContactMethod").fieldname
Just haven't used the table and query def objects enough to know where to
look.
 
You do realise that you can set the Row Source Type of the combo to Field
List, and it lists the field names?

To list the fields in a table:

Function ShowFields(strTable As String)
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set tdf = DBEngine(0)(0).TableDefs(strTable)
For Each fld In tdf.Fields
Debug.Print fld.Name
Next
Set tdf = Nothing
End Function
 
Back
Top