Click to See Complete Forum and Search --> : How do I know the number of columns in Access database using Visual Basic programming


Fumiryu
October 25th, 1999, 08:37 PM
Can anyone please tell how to count the number of COLUMNS in Access database by using Visual Basic programming? Thank you.

Praba S
October 26th, 1999, 01:34 AM
Try this
Change the names of mdb and table names.

Dim db As Database
Dim rs As Recordset
Set db = opendatabase("C:\Program Files\MSOFFICE\access\Samples\northwind.mdb")
Set rs = db.OpenRecordset("select * from customers", dbOpenSnapshot)
MsgBox CStr(rs.Fields.Count)
rs.Close
db.Close

Lothar Haensler
October 26th, 1999, 02:09 AM
you can inspect the TableDefs collection of the database object in DAO and query the fields.count property.