Solved

Retrieving Access field names - in correct order

Posted on 2006-10-30
5
272 Views
Last Modified: 2013-12-25
Hi Gurus

I'm using what I believe to be a fairly standard method of retrieving Access field names:

    DbsConnection.Provider = "Microsoft.Jet.OLEDB.4.0"
    strOpenMDb = "Data Source=" & FilePathAndName & ";Jet OLEDB:Database Password=" & Password
    DbsConnection.Open strOpenMDb

   ' Use OpenSchema and get the table names.
    Set rs = DbsConnection.OpenSchema(adSchemaColumns, Array(Empty, Empty, tDef_Onnet_DSLAMs))
   
   rs.MoveFirst
    Do While Not rs.EOF
        ThisCol = rs!COLUMN_NAME
        rs.MoveNext
    Loop

However, the order in which it fetches the columns is different to how the columns are displayed within Access.

What do I need to do in order to fetch the column names in the same order as Access - this is most important.
0
Comment
Question by:BrianBeck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17832987
Does this help any?

    Dim i As Integer
   
    For i = 0 To rs.Fields.Count - 1
        Debug.Print i+1,rs.Fields(i).Name
    Next i


0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17832998
urm, scrub that
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 300 total points
ID: 17833011
ok, here is an alternative way, it means u have to use DAO

    Dim db As DAO.Database
    Dim fld As DAO.Field
   
    Set db = DBEngine.Workspaces(0).OpenDatabase("C:\myremote.mdb"
    For Each fld In db.TableDefs("MyTable").Fields
        Debug.Print fld.Name, fld.OrdinalPosition
    Next fld
    db.Close
    set db=Nothing

the OrdinalPosition gives the position in the table
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17833016
urm missing closing round bracket on OpenDatabase,
doh!
0
 

Author Comment

by:BrianBeck
ID: 17833066
Thanks rockiroads - on the button!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question