Solved

Problem with code for listing field names

Posted on 2014-10-20
3
178 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 49

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 49

Expert Comment

by:Gustav Brock
ID: 40392227
You are welcome!

/gustav
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now