Hi,
Does anyone know how I can get a list of the fields in a table to go in a list box. I have been trying this but it doesn't work:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim cnt As Container
Dim doct As Document
Dim tbl As TableDef
Dim fld As Field
Dim fldrs As Field
Dim prop As Property
Set db = OpenDatabase("db1.mdb")
Set rs = db.OpenRecordset("Main")
Set fld = db.TableDefs(0).Fields(0)
Set fldrs = rs.Fields(0)
For Each prop In fld.Properties
Debug.Print prop.Name, prop.Type, prop.Value
Next
End Sub
I get a type mismatch error on the line:
Set fld = db.TableDefs(0).Fields(0)
I don't really understand the structure which I got from a help menu in Access. I am trying to list the names of tables in my database in a combo box. When the user selects one it lists the fields and types in another combo box. How do I do this? It is frustrating.
Thanks for any help.
Does anyone know how I can get a list of the fields in a table to go in a list box. I have been trying this but it doesn't work:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim cnt As Container
Dim doct As Document
Dim tbl As TableDef
Dim fld As Field
Dim fldrs As Field
Dim prop As Property
Set db = OpenDatabase("db1.mdb")
Set rs = db.OpenRecordset("Main")
Set fld = db.TableDefs(0).Fields(0)
Set fldrs = rs.Fields(0)
For Each prop In fld.Properties
Debug.Print prop.Name, prop.Type, prop.Value
Next
End Sub
I get a type mismatch error on the line:
Set fld = db.TableDefs(0).Fields(0)
I don't really understand the structure which I got from a help menu in Access. I am trying to list the names of tables in my database in a combo box. When the user selects one it lists the fields and types in another combo box. How do I do this? It is frustrating.
Thanks for any help.