Jump: Search:

Microsoft Access Developer Center

Table Design

Query Design

Form Design

Form Tips and Mistakes

Form Navigation Caption

Using a RecordsetClone

Synchronize Two Subforms

Late Bind Tab Subforms

Subform Reference to Control Rather than Field

Tab Page Reference

Shortcut Keys


Combo Box Top Tips

Properties and Validation

Select First Item

Cascading Combo Boxes

Zip, City, State AutoFill

Report Design

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

Add the NoData Event

Annual Monthly Crosstab Columns

Design Environment

Adding Buttons to the Quick Access Toolbar

Collapsing the Office Ribbon for more space

VBA Programming

Using Nz() to Handle Nulls

Avoiding Exits in the Body of a Procedure

Debugging Keys

Setting Module Options

Math Rounding Issues

Source Code Library

Microsoft Access Module VBA Library

Royalty Free VBA 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

Subsheet Name

Visual Source Safe

Deployment

Prevent Close Box

Disable Design Changes

Broken References

Simulating Runtime

Missing Package & Deployment Wizard

Microsoft Access Front-End Deployment

System Admin

Disaster Recovery Plan

Compact Database

Compact on Close

Database Corruption

Decompile Database

Bad DLL Calling Convention

Converting ACCDB to MDB

Cloud and Azure

Cloud Implications

MS Access and SQL Azure

Deploying MS Access Linked to SQL Azure

Visual Studio LightSwitch

LightSwitch Introduction

Comparison Matrix

Additional Resources

Microsoft Access Help

MS Access Developer Programming

More Microsoft Access Tips

Technical Papers

Microsoft Access Tools

Connect with Us

Email NewsletterEmail Newsletter

FMS Development Team BlogDeveloper Team Blog

Facebook PageFacebook

Twitter with FMSTwitter

 

 

Microsoft Access Subforms Should Reference the Control Rather than Field for Master Link Fields

Provided by: Luke Chung

Sample database: SubformMaster.zip (28K)

Link Master Field Should Reference the Control Rather than Field

Microsoft Access lets you quickly create forms displaying one-to-many relationships with subforms. Subforms are linked based on their Link Master Fields and Link Child Fields properties.

We recommend referencing the control rather than field when specifying the Link Master Field. This is different from the Link Child Field which should always be a field in the subform. For situations where the link master field is editable, a subform MUST be linked to the control rather than underlying field. Otherwise, the wrong data could be displayed or edited by the user.

What we're considering is how the subforms should reference the Master. Should it reference the control (txtMasterID) or the field name directly (EditableID) below?

Microsoft Access Subform Linked Master Field to Control
Linked on Control (Good)
Microsoft Access Subform Linked Master Field to Field
Linked Directly to Field (bad)

If the link master field were MasterID which is an autonumber field and can't be edited, this would not be an issue. However, if the field/control can be edited, it's critical that the Link Master Field uses the control name rather than the field name. It's also important that you rename the control so it's not the same name as the field name.

Background: Setting Up Subforms

One of the most powerful features of displaying data is the use of subforms. A subform is a form with its own data source that is embedded in another "master" form. From our sample database, open the form frmEditableMaster:

Microsoft Access Subform with Linked Master Field to Control and Field

This form uses the table tblMaster as its recordsource:

In the sample form, the field that's being used to link the subforms is the EditableID, rather than the MasterID. The two fields happen to contain the same information, but the EditableID field can be modified.

Referencing the Control is Critical if It Can be Edited

To see why referencing the control is important, open the form and change the value of the ID value from 22 to 23, then tab to the Description control:

Microsoft Access Subform Differences between Linked Master Field to Control vs. Field

The control's value has changed, but the underlying value in the table has not because the record is not saved. That only occurs when the user leaves the record. However, the subforms displayed on the screen are totally different. The one linked to the control (left) shows the records related to Master ID 23, while the one linked to the field (right), continues to show the saved value of 22.

By referencing the control, the subform linked on the control automatically updates when the control's value changes. This ensures the subform always reflects the displayed master field value.

By referencing the field, it's easy to get confused and think the subform records are related to the value when they aren't. Users think they're looking at data related to one master record, when they were really viewing another one. Who knows what bad decisions could result? Even worse, if the user adds, edits, or deletes records in the subform, they could completely mess up lots of data in the database.

Summary

The example is obviously quite trivial but displays the difference.

As a habit, you should rename the control to a different name from the field name, and always reference the control name rather than field as the Link Master Field.

Additional Resources

Good luck!

Feedback

Contact Us  l   Web questions: Webmaster   l   Copyright © FMS, Inc., Vienna, Virginia
Celebrating our 26th Year of Software Excellence