Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you query field names from a given table 2

Status
Not open for further replies.

Toga

Technical User
Jul 21, 2000
234
US
I need to query the field names of a given table so it list them in a column. I seem to remember this is possible but I don't remember how. Can anyone help please?

Many Thanks....Toga
 
I don't think you can do this in a query.

You can loop through the Fields collection of the TableDef in a module and write the fields out to another table.

You can run the Documentation tool and write the results to a table (it is File menu option). Fields will be listed for each table.

You can select a single record of the table, copy/paste into Excel, and then copy/Paste Special+Transpose just the headings.

John
 
Yes.....I thought of the Excel idea as well right after I posted the question......and did just what I needed. Thanks for your response.
Toga
 
Toga,

IF you wish to bypass Excel, you can get your field names by using a schema recordset.

Cheers,
Bill
 
Excel worked great and always looking to learn but what in the world is a schema recordset? That's a new one on me.

Could you provide a quick example of one?
 
I'm not sure what you mean by "list them in a column", but you can use a ListBox on a form or report and set its RowSourceType to "Field list". That's a very easy way to do it.

I'm not sure, but I think the "schema recordset" refers to using ADOX (ADO extensions) to process the "catalog". It's similar to scanning DAO TableDef and Field objects, but using ADO instead.

Here's some DAO code you could use to fill a text box with a vertical column of names:
Code:
    Dim db As DAO.Database, tdf As DAO.TableDef, fld As DAO.Field
    Dim strList As String

    Set db = CurrentDb()
    Set tdf = db.TableDefs("table name")
    For Each fld In tdf.Fields
        strList = strList & fld.Name & vbCrLf
    Next fld
    Set fld = Nothing
    Set tdf = Nothing
    Set db= Nothing
    [text box] = strList

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top