Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Table Sizes

Posted on 2013-12-04
14
Medium Priority
?
307 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
13 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

572 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