Fields in a table

  • Thread starter Thread starter Jim Pockmire
  • Start date Start date
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "MyTable"

Dim i As Integer
rs.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly

For i = 0 To rs.Fields.Count - 1
MsgBox rs.Fields(i).Name
Next
rs.Close
cnn.Close


--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| Can you provide code to make a list of the fields within a table?
|
|
 
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset
strSQL = "MyTable"

Dim i As Integer
rs.Open strSQL, cnn, adOpenForwardOnly, adLockReadOnly

For i = 0 To rs.Fields.Count - 1
MsgBox rs.Fields(i).Name
Next
rs.Close
cnn.Close
And for the lazy ones

Dim tbl as DAO.Tabledef
dim fld as DAO.Field
set tbl=currentdb.tabledefs("MyTable)
For each fld in tbl.Fields
MsgBox fld.Name
Next
set fld=nothing
set tbl=nothing
 
Back
Top