Solved

Object Definitions Update for 2010

Posted on 2013-01-20
2
265 Views
Last Modified: 2013-01-20
In Access 2003, a friend helped me to identify objects in a database with the code below.  It no longer works for Office 2010.  Can someone please help me update this code so it's functional and outputs to Excel 2010?

Function tableflds() As String
Dim Dbs As Database
Dim xlapp As Object
Dim hdr As Object
Dim tbls  As RecordsetDefs
Dim fld As Fields
Dim tbl As Integer, r As Integer, c As Integer
Dim x As Object, t As Object
Set Dbs = CurrentDb
Set tbls = Application.CurrentDb.TableDefs
Set xlapp = CreateObject("excel.Application")
xlapp.workbooks.Add
Set hdr = xlapp.activeworkbook.worksheets(1).range("A:A")
xlapp.Visible = True
c = 0
tbl = -1
For Each t In tbls
tbl = tbl + 1
r = 2
c = c + 1
hdr.cells(1, c).value = t.Name
Set fld = tbls(tbl).PageFields 'MOD: Changed from .fieldsl

For Each x In fld
hdr.cells(r, c).value = x.Name
r = r + 1
Next x
Set fld = Nothing
Next t
End Function
0
Comment
Question by:CFMI
2 Comments
 
LVL 39

Accepted Solution

by:
als315 earned 500 total points
Comment Utility
Try this code:
Public Function tableflds() As String
Dim xlapp As Object
Dim hdr As Object
Dim tbls  As Object
Dim fld As Object
Dim tbl As Integer, r As Integer, c As Integer
Dim x As Object, t As Object
On Error GoTo err1
tableflds = True
Set tbls = Application.CurrentDb.TableDefs
Set xlapp = CreateObject("excel.Application")
xlapp.workbooks.Add
Set hdr = xlapp.activeworkbook.worksheets(1).range("A:A")
xlapp.Visible = True
c = 0
tbl = -1
For Each t In tbls
tbl = tbl + 1
r = 2
c = c + 1
hdr.cells(1, c).Value = t.Name
Set fld = tbls(tbl).Fields 'MOD: Changed from .fieldsl

For Each x In fld
hdr.cells(r, c).Value = x.Name
r = r + 1
Next x
Set fld = Nothing
Next t
Exit Function
err1:
    tableflds = False
End Function

Open in new window

0
 
LVL 1

Author Closing Comment

by:CFMI
Comment Utility
Perfect.  Thanks.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

743 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

17 Experts available now in Live!

Get 1:1 Help Now