|
-
Oct 31st, 2000, 04:10 PM
#1
Thread Starter
New Member
How do you retrieve the field names from a recordset?
-
Oct 31st, 2000, 04:43 PM
#2
Hyperactive Member
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
-
Oct 31st, 2000, 05:08 PM
#3
New Member
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....
-
Oct 31st, 2000, 05:11 PM
#4
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|