Solved

Problem with code for listing field names

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

912 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

22 Experts available now in Live!

Get 1:1 Help Now