Access 2002: Get field name from ADO

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi folks,

Could anyone tell me how to get all the field name of a table from ADO and
display in msgbox?

Any help will be appreciated.

Thanks in advance.

Tim.
 
Public Sub ShowFieldNames()

Dim rst As ADODB.Recordset
Dim lngField As Long
Dim strFields As String

Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.Open "SELECT * FROM tblTest WHERE False"
For lngField = 0 To .Fields.Count - 1
If lngField = 0 Then
strFields = .Fields(lngField).Name
Else
strFields = strFields & ", " & .Fields(lngField).Name
End If
Next lngField
.Close
End With
MsgBox strFields

End Sub

Alternatively, you could use the OpenSchema method. The code required would
be more complex. It may be more efficient. But I doubt the difference would
be significant in most situations. If you want to check it out, here's a
link to the on-line documentation ...

http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthopenschema.asp
 
Back
Top