Solved

Problem with code for listing field names

Posted on 2014-10-20
3
190 Views
Last Modified: 2014-11-22
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(txtdatabasename)    
       Set rs2 = Currentdb.OpenRecordset("TableFieldNames")
       Currentdb.Execute ("DELETE TableFieldNames.* FROM TableFieldNames")

       For Each fld In db.TableDefs(cmbTable).Fields
             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).Fields

What am I doing wrong here?
0
Comment
Question by:dsoderstrom
  • 2
3 Comments
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40392173
You may need to modify to:

Dim fld As DAO.Field

/gustav
0
 

Author Closing Comment

by:dsoderstrom
ID: 40392222
That was the problem.
Thanks for the quick and accurate solution.
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40392227
You are welcome!

/gustav
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question