Help with ADOX.Catalog

G

Guest

Hey all

I think this was posted on the wrong forum originally; sorry for cross-posting. I'm trying to display a list of all the columns in a table using the ADOX Catalog. Here's the code I have

Set objConn = CurrentProject.Connectio
Set objCat = CreateObject("ADOX.Catalog"

objCat.ActiveConnection = objCon
Set objTbl = objCat.Tables(WhichTable

For Each objCol In objTbl.Column

strList = strList & ";" & objCol.Nam

Nex

WhichTable is a variable containing the name of the table I'm interested in

Now, this code WORKS, but the columns are added to the list in alpha order, instead of the order they are defined in the table itself. Is there any way to return the columns in the order that they appear in the table

Access 2000/Win2
 
E

Elwin

Fields have an 'OrdinalPosition' property which reflects
the order fields are displayed in, but I'm not sure your
Catalog object has access to it. The following function
makes use of the tabledef collection to return the same
string you're trying to get, but in the proper order.
Good luck.

Function GetFields(WhichTable As String) As String
Dim var As Variant
Dim strList As String
Dim i As Integer
For Each var In CurrentDb.tabledefs
If var.Name = WhichTable Then
For i = 0 To var.Fields.Count - 1
strList = strList & ";" & var.Fields(i).Name
Next i
End If
Next var
GetFields = Mid(strList, 2)
End Function

-----Original Message-----
Hey all,

I think this was posted on the wrong forum originally;
sorry for cross-posting. I'm trying to display a list of
all the columns in a table using the ADOX Catalog. Here's
the code I have:
Set objConn = CurrentProject.Connection
Set objCat = CreateObject("ADOX.Catalog")

objCat.ActiveConnection = objConn
Set objTbl = objCat.Tables(WhichTable)

For Each objCol In objTbl.Columns

strList = strList & ";" & objCol.Name

Next

WhichTable is a variable containing the name of the table I'm interested in.

Now, this code WORKS, but the columns are added to the
list in alpha order, instead of the order they are defined
in the table itself. Is there any way to return the
columns in the order that they appear in the table?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top