Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADOX and sorting the columns in the Access table 2

Status
Not open for further replies.

vladk

Programmer
May 1, 2001
991
0
0
US
Hi,

When I try to retrieve column names from the ACCESS table using ADOX, I get them in the alphabetical order.

And I need them in the order they are defined in the table.

Can anybody help me with this?

Thank you!
 
You coud try saving the names to an array
then sorting array

Peter Wallace
 
Peter Wallace

Thank you for the responce. How would I sort the array in the order of the fiedls in the Access table?

Thank you again

Vlad
 
Sory

Been Away

Sample sort

Dim C As Integer
dim I As Integer
For i = Ubound(Array) To 1 Step -1
For C = 1 To i
If (Array(C) < Array(C - 1) _
Or Len(LTrim(Array(C - 1))) = 0) _
And Len(LTrim(Array(C))) <> 0 Then
' Swap the names over
StrTemp = Array(C)
Array(C) = Array(C - 1)
Array(C - 1)=StrTemp
' swap them
End If
Next C
Next i
 
Um - you could use ADO instead, and read the fields collection of a recordset - that keeps them in the same order as in the underlying table
 
PeterWallace and strongm,

I apologize for not responding for several days!

Yes, I was aware of ADO, I tried it ahead of time with empty recordset and failed because I did MoveFirst first. It was one the reasons of posting the question. I did not realize that time that I still could loop through the fields on the empty recordset without MoveFirst and get the fields names in the "natural" table order.

strongm,

Thank for your responce, it made me try ADODB again.

PeterWallace,

Thank you for your example of code for sorting, it's always nice to have such things handy.

:0)

You all get the stars!

Thank you again!

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top