Solved

Table Sizes

Posted on 2013-12-04
14
239 Views
Last Modified: 2013-12-04
How do I find the sizes of my Access 2010 tables?
0
Comment
Question by:Chuck Wood
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 21
ID: 39696225
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
 
LVL 16

Author Comment

by:Chuck Wood
ID: 39696242
I want to determine each table's contribution to the size of the database.
0
 
LVL 13

Accepted Solution

by:
magarity earned 500 total points
ID: 39696337
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
 
LVL 21
ID: 39696360
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
 
LVL 16

Author Closing Comment

by:Chuck Wood
ID: 39696380
That works perfecly. Thank you.
0
 
LVL 84
ID: 39696382
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 16

Author Comment

by:Chuck Wood
ID: 39696388
TheHighTechCoach: Sorry but magarity beat you to the solution.
0
 
LVL 16

Author Comment

by:Chuck Wood
ID: 39696396
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
 
LVL 13

Expert Comment

by:magarity
ID: 39696458
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
 
LVL 21
ID: 39696489
@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
 
LVL 21
ID: 39696499
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
 
LVL 13

Expert Comment

by:magarity
ID: 39696604
Utteraccess is a specialty forum for ms access, not much of a direct competitor to a general site like EE.
0
 
LVL 21
ID: 39696869
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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 functions 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 Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

705 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