Click to See Complete Forum and Search --> : How do I populate a array?
yenni
Nov 20th, 2000, 08:10 AM
How do I create and populate an array with the fields of
a recordset?
paulw
Nov 20th, 2000, 08:25 AM
Use the fields collection. Assuming your recordset is called "rst".
Dim myFields(rst.Fields.Count - 1) As String
For i = 0 To rst.Fields.Count -1
myFields(i) = rst.Fields.Name
Next i
P.
yenni
Nov 20th, 2000, 10:44 AM
Thanks. Can I use that array in any other routine?
theroper
Nov 20th, 2000, 11:21 AM
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
yenni
Nov 20th, 2000, 12:56 PM
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
SysAdmin2
Nov 20th, 2000, 01:15 PM
The array is out of scope. If you want to access the arrary in other fuctions, you have to dim it public or global.
paulw
Nov 21st, 2000, 05:37 AM
Or better still, put it all in aclass and use Class methods...
Cheers,
P.
yenni
Nov 21st, 2000, 05:25 PM
Thanks y'all, much obliged
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.