Field Names

dtaylor

Active Member
Joined
Mar 21, 2002
Messages
379
Hello All,
Is there a way, with vba, to list the field names of a table?

Thanks

Dan
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi Russell,
I am using 2000 but coding this project in DAO (just do not like how adodb creates tables and querys).

Would it be to much to ask to show both?

Def would be benificial to me since my users are on both.

Thanks

Dan
This message was edited by dtaylor on 2003-01-23 12:37
 
Upvote 0
Here you go:


<pre>Option Compare Database
Option Explicit

Public Function PrintFieldsADO(strTableName As String)
Dim rst As ADODB.Recordset
Dim conn As Connection
Dim lngI As Long

Set rst = New ADODB.Recordset

rst.Open strTableName, CurrentProject.Connection, adOpenForwardOnly

With rst
For lngI = 0 To .Fields.Count - 1
Debug.Print .Fields(lngI).Name
Next lngI
.Close
End With

Set rst = Nothing

End Function

Public Function PrintFieldsDAO(strTableName As String)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim lngI As Long

Set db = CurrentDb
Set rst = db.OpenRecordset(strTableName, dbOpenForwardOnly)

With rst
For lngI = 0 To .Fields.Count - 1
Debug.Print .Fields(lngI).Name
Next lngI
.Close
End With

Set rst = Nothing
End Function</pre>

HTH,

Russell
 
Upvote 0

Forum statistics

Threads
1,221,510
Messages
6,160,226
Members
451,632
Latest member
purpleflower26

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