Solved

Retrieving Access field names - in correct order

Posted on 2006-10-30
5
256 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 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now