• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

Table Sizes

How do I find the sizes of my Access 2010 tables?
0
Chuck Wood
Asked:
Chuck Wood
  • 5
  • 4
  • 3
  • +1
1 Solution
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
Size? Are you referring to record counts?

Try:

Dim tbl As TableDef
Dim db As Database
Dim tblCount As Long

Set db = CurrentDb()

For Each tbl In db.TableDefs
    
    If Left(tbl.Name, 4) <> "MSys" Then  'do not include system tables.
        tblCount = DCount("*", tbl.Name)
        Debug.Print tbl.Name; tblCount
    End If
Next

db.Close
Set db  

Open in new window

0
 
Chuck WoodAuthor Commented:
I want to determine each table's contribution to the size of the database.
0
 
magarityCommented:
I found this script someone made that will tell you the sizes of the tables (at the bottom of the thread):
http://www.utteraccess.com/forum/Determine-Table-Size-t1938952.html

Access does not have any built in management tool that will tell you with just a few clicks.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
OK. There really is no built-in way to do this that I am aware of.

The most accurate way I have found is:

1) Create a new blank database
2) Close the database
3) Get the size of it empty.
4) Import a single table
5) Compact the database
6) Close the database
7) Get the size of the database and subtract the size when empty.

This can be automated with code:

Here is code for an MDB:
** Note is does not do the compact before getting the length

'---------------------------------------------------------------------------------------
' Procedure : ListAllTables_Size
' Author    : Gustav(original)
' Created   : 11/15/2009
' Purpose   : To get approximate sizes of all
'non-MSys tables in an Access mdb.
'Outputs table names and sizes  to immediate window.
'
'From AccessD discussion-
'---------------------------------------------------------------------------------------
' Last Modified:
'
' Inputs: N/A
' Dependency: Microsoft DAO 3.6 Object Library
'------------------------------------------------------------------------------
'
Public Sub ListAllTables_Size()

  Dim dbs As DAO.Database
  Dim tdf As DAO.TableDef
  
  Dim strName As String
  Dim strFile As String
  Dim strPath As String
  Dim lngBase As Long
  Dim lngSize As Long
    
   On Error GoTo ListAllTables_Size_Error

  Set dbs = CurrentDb
  strName = dbs.Name
  strPath = Left(strName, Len(strName) - Len(dir(strName)))
  
  ' Create empty database  to measure the base file size.
  strFile = strPath & "base" & ".mdt"
  CreateDatabase strFile, dbLangGeneral
  lngBase = FileLen(strFile)
  Kill strFile
  Debug.Print "Base size", lngBase
  
  For Each tdf In dbs.TableDefs
    strName = tdf.Name
    ' Apply some filtering - ignore System tables.
    If Left(strName, 4) <> "MSys" Then
      strFile = strPath & strName & ".mdt"
      Debug.Print strName,;
      CreateDatabase strFile, dbLangGeneral
      DoCmd.TransferDatabase acExport, "Microsoft Access", strFile, acTable, strName, strName
      lngSize = FileLen(strFile) - lngBase
      Kill strFile
      Debug.Print lngSize
    End If
  Next
  
  Set tdf = Nothing
  Set dbs = Nothing

   On Error GoTo 0
   Exit Sub

ListAllTables_Size_Error:

    MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure ListAllTables_Size "
  
End Sub

Open in new window




Editing records by adding data to a field can  cause a record to grow and use more space.  Not just by adding new records cause a table to grow.

Note: Unless every field in the table is filled to the max, every record will not use the same about of space.

To estimate the maximum size a table could use is possible if there are no memo fields or attachment fields.  You add up the max length of all the fields. Multiple that by the record.

Curious,  why do you need to know this?

TIP: The more we understand about what you are doing the better advice we can give.

Is your database split?
Is the  back end or un-split database getting over 1 GIG?
0
 
Chuck WoodAuthor Commented:
That works perfecly. Thank you.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
What's the end goal of this? Just curious, really, as your search, and HTC's suggestions, are about the only way to do this.
0
 
Chuck WoodAuthor Commented:
TheHighTechCoach: Sorry but magarity beat you to the solution.
0
 
Chuck WoodAuthor Commented:
LSMConsulting: My end goal is to find table sizes so I can determine where to archive data as several of our Access databases approach the maximum size of 2 GB. You are correct as magarity, then HTC, provided the solution to meet my goal.
0
 
magarityCommented:
I recommend people reaching the 2GB limit in Access should seriously consider SQL Server Express which is free from Microsoft, interacts well with Access, and has a 10GB limit.
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
@magarity,

You posted a link to a "competing" site and that violates the rules of EE. Don't be surprised if the link is deleted.
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
cwood-wm-com,


TheHighTechCoach: Sorry but magarity beat you to the solution.
Yup. It took me longer because I WAS follow the EE rules  of not posting a link to a competing site.
0
 
magarityCommented:
Utteraccess is a specialty forum for ms access, not much of a direct competitor to a general site like EE.
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
In EE's  view it is direct competition for the Access section.  I have had links deleted.

I got the message about a previous post I made:


Links to competing Q&A web sites are discouraged. They are subject to deletion unless accompanied by a substantial body of discussion in the EE post.

See this writeup in a recent newsletter for more information:

http://www.ee-stuff.com/Newsletter-old/091113newsletter.htm#tipsfrom

SouthMod
EE Moderator
SouthMod@e-e.com
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now