|
-
Nov 20th, 2000, 09:10 AM
#1
Thread Starter
Lively Member
How do I create and populate an array with the fields of
a recordset?
-
Nov 20th, 2000, 09:25 AM
#2
Fanatic Member
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...
-
Nov 20th, 2000, 11:44 AM
#3
Thread Starter
Lively Member
Thanks. Can I use that array in any other routine?
-
Nov 20th, 2000, 12:21 PM
#4
New Member
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
-
Nov 20th, 2000, 01:56 PM
#5
Thread Starter
Lively Member
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
-
Nov 20th, 2000, 02:15 PM
#6
Junior Member
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.
-
Nov 21st, 2000, 06:37 AM
#7
Fanatic Member
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...
-
Nov 21st, 2000, 06:25 PM
#8
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|