Field Names

coyotem78

New Member
Joined
Sep 9, 2002
Messages
44
Hi

In VBA, is there a way to get the field names from an existing table?

thanx

coyotem78
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,

Here's one way. To get the code to work you need to set a reference to the Microsoft ADO Ext 2.n For DDL and Security by choosing Tools, References and then selecting it.

Code:
Sub GetFieldnames()

    Dim adoxCat As ADOX.Catalog, adoxTable As ADOX.Table, adoxColumn As ADOX.Column

    Set adoxCat = CreateObject("ADOX.Catalog")

    adoxCat.ActiveConnection = CurrentProject.Connection

    Set adoxTable = adoxCat.Tables("tblDepotData")

    For Each adoxColumn In adoxTable.Columns

        Debug.Print adoxColumn.Name

    Next adoxColumn


End Sub
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,341
Members
451,638
Latest member
MyFlower

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top