Results 1 to 4 of 4

Thread: Field Names

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Location
    SANTA ANA
    Posts
    14

    Angry

    How do you retrieve the field names from a recordset?

  2. #2
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274

    This will build an array of your field names..

    for n = 0 to adodc.recordset.recordcount - 1

    myarray(n) = adodc.recordset.fields(n).name

    next

  3. #3
    New Member
    Join Date
    Oct 2000
    Posts
    6

    I'm not sure about the above code because I don't use ADO much - I still use DAO mostly... But to me it looks as if the above code is looping through the entire recordset when you only want to loop through a fields collection...

    Here's a good way to do it using DAO...
    --------------------------------------------------------
    Dim db as Database
    Dim dbRS As Recordset
    Dim NumOfFields As Integer
    Dim X As Integer
    Dim arrayFieldNames() As String

    Set db = OpenDatabase(YourDatabasesPath)
    Set dbRS = dbProbe.OpenRecordset("YourRecordsetsName", _ dbOpenDynaset)

    NumOfFields = dbRS.Fields.Count

    ReDim arrayFieldNames(0 To NumOfFields - 1)

    For X = 0 To NumOfFields - 1
    arrayFieldNames(X) = dbRS.Fields(X).Name
    Next X
    ----------------------------------------------------------

    If your reading the names into a control or something you could just add them during the loop instead of using an array to store them....


    Hope this helps....

  4. #4
    New Member
    Join Date
    Oct 2000
    Posts
    6

    Corrected...


    the line that read Set dbRS = dbProbe.OpenRecordset etc...
    Should read Set dbRS = db.OpenRecordset ---- etc.. etc...
    The probe part was because I was writing a recent
    database where the name of the database object was dbProbe... It was probably obvious to you anyways
    Just thought I'd post the correction anyway.
    The corrected version is below.


    Dim db as Database
    Dim dbRS As Recordset
    Dim NumOfFields As Integer
    Dim X As Integer
    Dim arrayFieldNames() As String

    Set db = OpenDatabase(YourDatabasesPath)
    Set dbRS = db.OpenRecordset("RecordsetName", _ dbOpenDynaset)

    NumOfFields = dbRS.Fields.Count

    ReDim arrayFieldNames(0 To NumOfFields - 1)

    For X = 0 To NumOfFields - 1
    arrayFieldNames(X) = dbRS.Fields(X).Name
    Next X

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