Column Listing using VBA

TarBall

Registered User.
Local time
Today, 06:45
Joined
Jul 25, 2005
Messages
11
I would like to get a list of a tables columns using VBA. How can I do this in VBA? I understand how to get a list of tables in the table collection but is there a way to access a particular tables definition to produce a list of columns?

My goal is to select a table, generate its column definitions in list then use the list to drive a conversion routine of data in the selected column.

I have a ton of spreadsheets to convert from one set of codes to their corresponding short_descriptions. I have loaded the spreadsheets containing the code/short description translation. Since each spreadsheet has a variable number of columns containing codes to translate I want to use a form to select the table (corresponding to a loaded spreadsheet) and then based on that selection, check the columns to convert. I have the routine down but its hard coded and now I want to generalize it into a function.

Thanks for the help.
 
I figured it out so I thought I would post the code for others. Here is how to get the column names from a table in your database tabledef collection.

Code:
Dim Counter as long
Counter=0

For Each tdf In Application.CurrentDb.TableDefs
If tdf.Name = "tblMappings" Then

   While Counter < tdf.Fields.Count
        Debug.Print "Fields: " & tdf.Fields(Counter).Name
        Counter = Counter + 1
   Wend
End If
Next
 
Last edited:

Users who are viewing this thread

Back
Top Bottom