Hi, I'm new to the world of ADO. I'm trying to figure out, how to retrieve the fieldnames that exist in an MSAccess table without previously knowing what they are.
Reason being, more could be added at a later date and I wanted to write code that was flexible enough to count the number of fields, and within a loop find the field names one by one, and then be able to access the data.
Can anyone please offer some advice on how this can be done? Or if it's even possible?
Also, is there a way to create a new Table and assign new fieldnames?
Thanks
06-08-2002 at 12:23 PM
|
JLRodgers Level: Moderator Registered: 04-04-2002 Posts: 1617
Re: Retrieving fieldnames Archived to Disk
' Field Names
Dim i As Integer
Dim ars As New ADODB.Recordset
For i = 0 To ars.Fields.Count
Debug.Print ars.Fields(i).Name
Next
' Tables (although some Access versions and SQL differ)
adodcCN.Execute "CREATE TABLE tablename (field1 as type, ..., fieldx as type)"
06-08-2002 at 08:17 PM
|
ASHISH25 Level: Guest
Re: Retrieving fieldnames Archived to Disk
' Find the Field Names
Dim i As Integer
Dim rs As New ADODB.Recordset
For i = 0 To rs.Fields.Count
Debug.Print rs.Fields(i).Name
Next
' Tables creation
cn.Execute "CREATE TABLE tablename (field1 as type, ..., fieldx as type)"
[Edited by ASHISH25 on 09-08-2002 at 10:27 AM GMT]