Solved

Table Sizes

Posted on 2013-12-04
14
287 Views
Last Modified: 2013-12-04
How do I find the sizes of my Access 2010 tables?
0
Comment
Question by:Chuck Wood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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
 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

734 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