Solved

Retrieving Access field names - in correct order

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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