dsoderstrom
asked on
Problem with code for listing field names
I am trying to find the field names in a table in an Access database other than the current database and write these field names into a table in the current database.
I am using the following code:
Dim fld As Field
Dim db As DAO.Database
Dim rs2 As DAO.Recordset
Set db = OpenDatabase(txtdatabasena me)
Set rs2 = Currentdb.OpenRecordset("T ableFieldN ames")
Currentdb.Execute ("DELETE TableFieldNames.* FROM TableFieldNames")
For Each fld In db.TableDefs(cmbTable).Fie lds
rs2.AddNew
rs2!NamofTable = cmbTable
rs2!NameOfField = fld.Name
rs2.Update
Next fld
rs2.close
Variable txtdatabasename contains the full path for the database that the table is in.
Variable cmbTable contains the name of the table.
I am getting the error message "Run-time error '13': Type mismatch" on the following line:
For Each fld In db.TableDefs(cmbTable).Fie lds
What am I doing wrong here?
I am using the following code:
Dim fld As Field
Dim db As DAO.Database
Dim rs2 As DAO.Recordset
Set db = OpenDatabase(txtdatabasena
Set rs2 = Currentdb.OpenRecordset("T
Currentdb.Execute ("DELETE TableFieldNames.* FROM TableFieldNames")
For Each fld In db.TableDefs(cmbTable).Fie
rs2.AddNew
rs2!NamofTable = cmbTable
rs2!NameOfField = fld.Name
rs2.Update
Next fld
rs2.close
Variable txtdatabasename contains the full path for the database that the table is in.
Variable cmbTable contains the name of the table.
I am getting the error message "Run-time error '13': Type mismatch" on the following line:
For Each fld In db.TableDefs(cmbTable).Fie
What am I doing wrong here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome!
/gustav
/gustav
ASKER
Thanks for the quick and accurate solution.