?
Solved

Retrieving Access field names - in correct order

Posted on 2006-10-30
5
Medium Priority
?
290 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
  • 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 1200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 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