Click to See Complete Forum and Search --> : how to generate a list of all fields in a table (to be added to a listbox)


chasilbao
February 3rd, 2000, 08:31 AM
how to generate a list of all fields in a table (to be added to a listbox)

Lothar Haensler
February 3rd, 2000, 08:38 AM
if you use DAO you can iterate over the Fields collection that's part of the TableDef object.

Johnny101
February 3rd, 2000, 09:37 AM
You could use the fields collection off the recordset object in ADO...


Dim x as Integer
Dim rs as ADODB.Recordset
'get an empty recordset
'select * from table where 1=2

for x = 0 to rs.Fields.Count - 1
ListBox1.AddItem rs.Fields(x).Name
next x

'...




You could also use the OpenSchema method of the connection object, but im not convinced that way is any faster than the above way. It might however, be more memory efficient, I haven't tested it.

John

John Pirkey
MCSD
www.ShallowWaterSystems.com