Summary of contents of mdb file

  • Thread starter Thread starter simonc
  • Start date Start date
S

simonc

I'm looking through a database which is used by a piece of software I don't
have. There are 63 tables, many of which are empty and most of which have
names which don't give obvious clues as to what they're for. Is there an easy
way of outputting basic statistics of this database - ie for each table a
list of the fields and the number of records it contains?

Grateful for assistance.
 
simonc said:
I'm looking through a database which is used by a piece of software I
don't
have. There are 63 tables, many of which are empty and most of which have
names which don't give obvious clues as to what they're for. Is there an
easy
way of outputting basic statistics of this database - ie for each table a
list of the fields and the number of records it contains?

Grateful for assistance.


The built-in Documenter will give you a list of fields, but not the number
of records. Here's some example code that will list table names, number of
records, and field names ...

Public Sub ListTables(ByVal DatabaseName As String, ByVal OutputFile As
String)

Dim db As DAO.Database
Dim intFile As Integer
Dim tdfs As DAO.TableDefs
Dim tdf As DAO.TableDef
Dim rst As DAO.Recordset
Dim flds As DAO.Fields
Dim fld As DAO.Field

If DatabaseName = CurrentProject.FullName Then
Set db = CurrentDb
Else
Set db = DBEngine.OpenDatabase(DatabaseName)
End If

intFile = FreeFile

'this will over-write any existing file with the specified name, use
with care
Open OutputFile For Output As intFile

Set tdfs = db.TableDefs
For Each tdf In tdfs
If LCase$(Left$(tdf.Name, 4)) <> "msys" Then
Print #intFile, "Table: " & tdf.Name
Set rst = db.OpenRecordset("SELECT Count(*) FROM " & tdf.Name)
Print #intFile, "Records: " & rst.Fields(0)
rst.Close
Print #intFile, "Fields:"
Set flds = tdf.Fields
For Each fld In flds
Print #intFile, , fld.Name
Next fld
Print #intFile,
End If
Next tdf
Close #intFile
If DatabaseName = CurrentProject.FullName Then
db.Close
End If
MsgBox "Finished"

End Sub

Example of use, in the Immediate window ...

listtables "c:\SomeFolder\SomeFile.mdb", "c:\SomeFolder\SomeFile.txt"

.... where "SomeFile.mdb" is the database you want to analyse, and
"SomeFile.txt" is the name of the text file to which the output will be
written. Note that this will over-write any existing file with that name, so
be careful.
 
Simon, here's my preferred approach for getting a picture of a database
schema:
Relationship Report with extended field information
at:
http://allenbrowne.com/AppRelReport.html

It's like the Relationships diagram, but gives extended information,
including the count of records in each table, data types of each field, and
details of indexes and properties of the fields.

You are probably aware of the built-in analyzer which lists the fields, or
here's a better one that Jeff Conrad put together:
http://www.accessmvp.com/JConrad/accessjunkie/csdtools.html
 
Brendan

Thanks for this code which I'm sure will eventually provide what I need. The
immediate problem is that when I pasted the code into Visual Basic Editor it
gave error messages about missing reference to the file dao2535.tlb version
3.5.

I presume my version of Access, which is 2002, is in someway not compatible
with some of the commands. Could you advise which bits I might need to change.

Many thanks.
 
simonc said:
Brendan

Thanks for this code which I'm sure will eventually provide what I need.
The
immediate problem is that when I pasted the code into Visual Basic Editor
it
gave error messages about missing reference to the file dao2535.tlb
version
3.5.

I presume my version of Access, which is 2002, is in someway not
compatible
with some of the commands. Could you advise which bits I might need to
change.


That's the DAO 2.x/3.x compatibility library, which was used to enable old
DAO 2.x (Access 2 vintage) code to work with later versions of DAO and
Access. Are you trying to run the code within the database you're trying to
analyze? As you say that database is used by a third-party app, I'd advise
not messing with it. I recommend adding the code to a new empty database
instead. You'll need a reference to the Microsoft DAO 3.6 Object Library,
not the compatibility library. To view existing references, and add or
remove them as necessary, open the VBA editor, choose Tools from the menu
bar, then References.
 
Thanks for this advice. And don't worry, it was a copy of the database I
pasted the code into.

I've done something wrong, however. I pasted the code in as a module but
when I run it in the Immediate window it says it expected a variable or a
procedure, not a module. However, I can't insert a procedure because that
option is greyed out.

Grateful for more help. I'm almost there...
 
simonc said:
Thanks for this advice. And don't worry, it was a copy of the database I
pasted the code into.

I've done something wrong, however. I pasted the code in as a module but
when I run it in the Immediate window it says it expected a variable or a
procedure, not a module. However, I can't insert a procedure because that
option is greyed out.

Grateful for more help. I'm almost there...


Perhaps you gave the module the same name as the procedure? If so, just
rename the module.
 
You are right. That's exactly what I had done. It now works perfectly. Many
thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top