Results 1 to 8 of 8

Thread: How do I populate a array?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100
    How do I create and populate an array with the fields of
    a recordset?

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Use the fields collection. Assuming your recordset is called "rst".

    Code:
    Dim myFields(rst.Fields.Count - 1) As String
    
    For i = 0 To rst.Fields.Count -1
      myFields(i) = rst.Fields.Name
    Next i
    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100
    Thanks. Can I use that array in any other routine?

  4. #4
    New Member
    Join Date
    Aug 2000
    Posts
    15
    Why not use the recordset as an array...

    I.e. disconnect the recordset from the database

    Then you have all the added functionality of a recordset

    like eof,bof,movenext,movelast,movefirst etc


  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100
    Because I want to display fields in the rst and I'm having
    problems displaying such on a form with scrollbars, so I
    thought I would use an array.
    When I tried Paulw code, I got an "Expected array" error
    when I used the array in a different subroutine
    e.g.. when I declare the array in sub GetArray, and try to
    access it in sub Scroll, i get the error.

    [code]
    Sub GetArray()
    Dim rr(rst.Fields.Count - 1) As String
    For i = 0 To rst.Fields.Count - 1
    rr(i) = rst.recno
    Next i
    End Sub

    Sub Scroll()
    For a = 1 To rst.RecordCount
    Print rr(a)
    Next
    End Sub

  6. #6
    Junior Member SysAdmin2's Avatar
    Join Date
    Mar 2000
    Location
    Plainfield, IL, USA
    Posts
    26

    Out of Scope

    The array is out of scope. If you want to access the arrary in other fuctions, you have to dim it public or global.

  7. #7
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Or better still, put it all in aclass and use Class methods...

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100

    Thumbs up

    Thanks y'all, much obliged

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