Microsoft Access Products Microsoft Access Database Architecture: Taking Time into Account and Shadow Tables

Provided by Luke Chung, President of FMS, Inc.

When designing an application and its tables, it's very important to capture the time dimension and determine how data should be stored with the expectation that it will change over time. While there's a natural tendency to keep data normalized so that the same information is stored in only one place, the time dimension also needs to be considered.


Microsoft Access Time

A common example is the use of a Customer table where a Customer ID field identifies the record, which contains the person's name, address, etc. An invoice table could include a Customer ID that identifies the customer. While this approach works if the address changes; the Customer record is updated and all his/her invoices reflect the new address; a problem arises if there's a need to go back and find out where a previous shipment was sent. If a backup of the original customer record or the original customer data is not maintained with the original invoice, that information is lost.

While some information may not be worth keeping, old phone numbers for example, other pieces could be critical. For instance, a list of products and prices can be used for new sales, but a copy of the data needs to be kept in the invoice's line items so that a change in the prices does not cause old invoices to change. Thinking about what is important and is not is a crucial part of the design process, and very difficult to fix later.

One way to address this is to make a copy of the original customer record in the invoice table. This essentially takes a snapshot of the data and preserves it, making it easy to access the old invoice and see exactly what data was used at the time of creation or shipment.

Another approach is to presume the data does not change that often and when you reprint the invoice you want to show the new address, not the old one. If that's the case, this could be solved by simply keeping a shadow Customer table, so that any changes to the customer record (or relevant fields) are documented along with the time and user who did it. If historic information is required, it would be a simple search in the table to find it.

A shadow table is essentially the same as the original table with some small differences:

  • It has a it's own primary key field (AutoNumber). This allows it to store multiple versions of the same record ID from your master table without creating a unique primary key violation.
  • All secondary indexes that require uniqueness need to have that constraint removed
  • Any extra fields you may want to add to track the activity (e.g. the action performed, who and when it occurred).
  • Eliminate any field validation requirements, null prevention, etc. that would prevent a new record from being saved in this table. We want to save all changes here. We don't care about validation in this table. That's something that needs to be handled where the user makes their edits

One can then create a simple parameterized query that takes all the fields from the master table and inserts it into the shadow table for a particular record (e.g. InvoiceID).

Then, but adding VBA code to form's AfterUpdate event, the query can be invoked with the current record's ID to copy the record to the shadow table.

In SQL Server, a trigger can be created for each table to automatically store a copy in another table. This is more robust since any time the data is modified, this audit record is created. In Access using Jet tables, this is less robust since people may be able to edit the records without going through your data entry form.


Additional Resources

Table Design

Query Design

Form Design

Form Tips and Mistakes

Copy Command Button and Keep Picture

Module VBA to Forms and Controls

Form Navigation Caption

Resync Record in a Subform

Synchronize Two Subforms

Multiple OpenArgs Values

Late Bind Tab Subforms

Subform Reference to Control Rather than Field

Tab Page Reference

Shortcut Keys


Combo Box Top 6 Tips

Properties and Validation

Select First Item

Cascading Combo Boxes

Zip, City, State AutoFill

Report Design

Suppress Page Headers and Footers on the First Page of Your Report

Add the NoData Event

Annual Monthly Crosstab Columns

Design Environment

Add Buttons to the Quick Access Toolbar

Collapse the Office Ribbon for more space

VBA Programming

Basics: Forms and Controls

Run VBA Code from a Macro

Use Nz() to Handle Nulls

Avoid Exits in the Body of a Procedure

Shortcut Debugging Keys

Set Module Options

Math Rounding Issues

Rename a File or Folder

Avoid DoEvents in Loops

Age Calculations

Weekday Math

Send Emails with DoCmd.SendObject

Source Code Library

Microsoft Access Modules Library

Microsoft Access Modules

VBA Error Handling

Error Handling and Debugging Techniques

Error Number and Description Reference

Basic Error Handling

Pinpointing the Error Line

Performance Tips

Linked Database

Subdatasheet Name

Visual SourceSafe

Deployment

Runtime Downloads

Simulate Runtime

Prevent Close Box

Disable Design Changes

Broken References

Remote Desktop Connection Setup

Terminal Services and RemoteApp Deployment

Reboot Remote Desktop

Missing Package & Deployment Wizard

Avoid Program Files Folder

Unavailable Mapped Drives

Microsoft Access Front-End Deployment

System Admin

Disaster Recovery Plan

Compact Database

Compact on Close

Database Corruption

Remove 'Save to SharePoint Site' Prompt from an Access Database

Class Not Registered Run-time Error -2147221164

Inconsistent Compile Error

Decompile Database

Bad DLL Calling Convention

Error 3045: Could Not Use

Converting ACCDB to MDB

SQL Server Upsizing

Microsoft Access to SQL Server Upsizing Center

Microsoft Access to SQL Server Upsizing Center

When and How to Upsize Access to SQL Server

SQL Server Express Versions and Downloads

Cloud and Azure

Cloud Implications

MS Access and SQL Azure

Deploying MS Access Linked to SQL Azure

SQL Server Azure Usage and DTU Limits

Visual Studio LightSwitch

LightSwitch Introduction

Comparison Matrix

Additional Resources

Connect with Us

 

Free Product Catalog from FMS