Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Posts
    31

    Unanswered: Query that return table FieldName

    Is there a way to run a query that return the FieldName's of a table, not the data but the fieldname?

    For example; say you have a table called People that has the following fields: Name, City, State, ZipCode.

    Can I return the fieldnames within a query not the data within the fields?

    Thanks

  2. #2
    Join Date
    Apr 2003
    Location
    Santa Barbara, CA
    Posts
    67

    Re: Query that return table FieldName

    Originally posted by eciabattari
    Is there a way to run a query that return the FieldName's of a table, not the data but the fieldname?

    For example; say you have a table called People that has the following fields: Name, City, State, ZipCode.

    Can I return the fieldnames within a query not the data within the fields?

    Thanks
    create table tblFieldNames with field Fname text 50

    Function FieldNames()
    Dim db As Database, src As Recordset, des As Recordset, i%
    Set db = CurrentDb()
    Set src = db.OpenRecordset("Table1")
    Set des = db.OpenRecordset("tblFieldNames")
    For i = 0 To src.Fields.Count - 1
    des.AddNew
    des!Fname = src.Fields(i).Name
    ' capture other properties by adding fields to Destination Table and using .(property name)
    des.Update
    Next
    src.Close
    des.Close
    db.Close
    Set src = Nothing
    Set des = Nothing
    Set db = Nothing
    End Function

  3. #3
    Join Date
    Apr 2003
    Posts
    31

    Thanks

    Works perfectly. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •