My.ADVISOR.com Sign-In
ID
Password

Member Center / Sign-Up
   
SUBSCRIPTION STATUS
If you are a subscriber to this publication, sign-in to access locked articles. To subscribe or renew go to www.AdvisorStore.com.
Go to Article

DATABASE DESIGN

Eliminate Bloat by Using Temporary Databases in Microsoft Access

Using temporary tables in your Access database can lead to database bloat. This technique leverages built-in features of Microsoft Windows to eliminate the problem.

  DOWNLOAD: Get an example file you can use to follow along with this article.
Subscribers: Sign-in to activate download link
By Doug Steele

I'm sure many of you have had situations where you needed to get data from an external source into your application but, for a variety of reasons, it wasn't possible to link to the data: It had to be imported. At the same time, you might have needed to do something with that new data, such as:

  • Run queries to take the data and write it to multiple existing tables in your application.
  • Do validations on the values in the table.

So, you didn't actually require the imported data to exist in its original form after you were done. Although you can import the data into a temporary table and work from there, if the import is something that needs to be done on a regular basis, adding the data to the temporary table and subsequently deleting it quickly leads to bloat in your database.

What you might consider doing in such cases is putting your temporary table into a temporary database. That is, after you're done with the raw imported data, you simply delete the temporary database to minimize the impact on your production database. I'm going to give you all the code you need to create such a temporary database by taking advantage of some Windows API calls (and using yet another MP3-related example).

Setting the scene

Those of you who use Windows Media Player (WMP) as the player on your computer might not be aware there's a method of querying the entries in Media Player. I'm going to create a process that gets the details of all the Audio entries and stores those details in a temporary table in a temporary database, then refreshes the "permanent" table with new information. In the refresh, Access updates entries retrieved earlier with the most up-to-date information and adds new entries.

Conceptually, the code is pretty simple. It includes:
  • A function to get the name of the file to use for the temporary database (CreateTempFilename)
  • A routine to create a temporary table in the temporary database and create a linked table in the application database to work with that temporary table (CreateTempTableDDL)
  • A routine to write data to the temporary table (WMPToAccess)
  • Code to update the "permanent" table, based on the data in the temporary table (ProcessDifferences)

The controlling routine ProcessData uses these routines to manage the temporary table and, after all that's complete, to delete the temporary database and remove the linked table:

Sub ProcessData()

Dim strTemporaryFile As String

  strTemporaryFile = CreateTempFilename()

  If Len(strTemporaryFile) > 0 Then
    Call CreateTempTableDDL(strTemporaryFile)
    If WMPToAccess() > 0 Then
      Call ProcessDifferences
    End If
  End If

  If Len(strTemporaryFile) > 0 Then
    Kill strTemporaryFile
  End If
  If TableExists("WMPLoad") Then
      CurrentDb.TableDefs.Delete "WMPLoad"
  End If

End Sub

Doug Steele has worked for many years with databases on mainframes and PCs. He has been recognized as an Access MVP for his contributions to Microsoft-sponsored newsgroups. http://I.Am/DougSteele AccessHelp@rogers.com

Printer-friendly
page layout

Eliminate Bloat by Using Temporary Databases

No reader comments ... yet.

    What do YOU think about this topic? Share your advice and thoughts using this form.

    Your Name

    REQUIRED : PUBLIC

    Your E-Mail

    REQUIRED : PRIVATE

    Job, Company

    OPTIONAL : PUBLIC

    City, State, Country

    OPTIONAL : PUBLIC

    Your Web Site

    OPTIONAL : PUBLIC

    Your Comment

    Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


    Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

    ARTICLE INFO

    Web Edition: 2007 Week 15, Doc #18944

    FREE ACCESS FREE ACCESS

      DOWNLOAD: Get an example file you can use to follow along with this article.
    Subscribers: Sign-in to activate download link

    Keyword Tags: Database Management, Microsoft, Microsoft Access, Microsoft Access Development, Microsoft Office, Microsoft Office Access, Microsoft Windows, Programming, Temporary databases, VBA

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2010 Advisor Media, LLC. All Rights Reserved.
    Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
    ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, LLC in the United States and/or other countries.
    Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
    Hosted by Prominic.NET Website powered by
    LOTUS SOFTWARE
    ztmsad0705 steed23 posted 2007-4-9 mod 03/15/2010 03:11:00 AM ztdbms/ztdbms
    domino-144.advisor.com my.advisor.com 03/21/2010 09:24:19 PM