Results 1 to 4 of 4

Thread: Retreiving Field Names from a DB

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    Hi;
    I was wondering how can one retreive Field name in a db (column name) (access or Sql) .
    In clearer terms , suppose you have a DB with one or more tables... we are only interested in "TableX" ... which has
    Z number of fields. I want to be able to retrieve those fields name
    trough VB code ... thus having a progam that does the following :

    - user provides table name and dB name
    - Program returns :

    " this table contains Z Fields "
    " here are the fields names "
    "field1"
    "field2"
    .... etc
    any help would be greatly apreciated
    - regards -
    - razzaj -

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84

    Cool

    1.) open a recordset(rs) that contain all fields of your table

    2.)
    Code:
    rs.Fields.Count
    gives you the number of fields

    3.) to get the fieldname use this:
    Code:
        For i = 0 To rs.Fields.Count - 1
           Debug.Print rs.Fields(i).Name
        Next i

    hope this helps

    [Edited by Nina on 08-21-2000 at 07:29 AM]

  3. #3

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Question Yes But

    ... I c .. but will that return to me the Value contained in this field of that record ... or The NAME of the Field in the TABLE ?? that is what I need ...
    I need the Name Of the Field the Column name that is ...
    - regards -
    - razzaj -

  4. #4
    Lively Member
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    84
    sorry, forgot to add the .name property...
    now it will give you name of the field

Posting Permissions

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



Click Here to Expand Forum to Full Width