tags:

views:

86

answers:

1

Hi guys,

I need to get all of the column names of a table using vba or Access SQL and iterate through them for validation, does anyone have a solution to this, I have searched google to no avail.

Any help much apriciated :)

+2  A: 

This will work

Set db = CurrentDb()
Set rs1 = db.OpenRecordset("Table1")
Dim fld As DAO.Field
For Each fld In rs1.Fields
    MsgBox (fld.Name)
Next
Set fld = Nothing
Alex DeLarge
Quick, Clean and exactly what I wanted, thank you! +1
Yoda
Good to hear it, you're welcome..
Alex DeLarge
I generally never use a counter for collections that have their own data type for the items in the collection. I'd use For Each fld In rs1.Fields, instead (with the variable fld as type DAO.Field).
David-W-Fenton
@David-W-Fenton agreed, I've edited my response accordingly..
Alex DeLarge
I've now edited it to fix an oversight in your edit (you omitted changing the counter variable to a field variable).
David-W-Fenton