Counting fieldnames of a table

raindrop3

Registered User.
Local time
Today, 11:29
Joined
Sep 6, 2001
Messages
98
Hello,

Does someone know the SQL-Statement to count howmany fields are in a table? (count the colomnames)

Thanks,

Albert
 
Try this:

Function CountFields(MyTable As String) As Integer
'*******************************************
'Name: CountFields (Function)
'Purpose: Returns the number of fields in table
'Inputs: From debug window:
' ? countfields("tblProducts")
'Returns: 6
'*******************************************

Dim db As DATABASE, td As TableDef, tName As String

Set db = CurrentDb
tName = MyTable
On Error Resume Next
Set td = db.TableDefs(tName)
If Not Err = 3265 Then 'table not found
CountFields = td.Fields.Count
End If
db.Close
Set db = Nothing
End Function
 
Raskew,

Thanks a lot for your quick response. It works great!

Albert
 
Uhhh, I thought I could figure it out myself, but no luck. How do I retrieve the names of the columns?

Thanks.

Albert
 
Adding to the previous code, immediately following the line reading CountFields = ...

Dim FieldName as string, fld as field
For Each fld In td.Fields
FieldName = fld.Name
debug.print FieldName
next fld

[This message has been edited by raskew (edited 12-17-2001).]
 

Users who are viewing this thread

Back
Top Bottom