logo
search
Others

How to Prevent an Access Form from Opening Without a Related Record

Maira MehtabMaira Mehtab Sep 28, 2026 869 views

Question details

The user needs to prevent a secondary bill-of-materials form from opening as a blank record when the selected material has no matching data in the database.

Product
Microsoft Access
Device & OS
not provided
Scenario
Clicking a command button on a main form to open a related bill-of-materials form based on a selected material format.
Observed behavior
If no pre-existing matching record is found for the selected material, the secondary form opens completely blank instead of displaying an error or blocking the action.
Before you start

Ensure that your tables are properly normalized and that the one-to-many relationship between your materials table and the bill-of-materials table is correctly established in your database relationships.

Solution 1Recommended

Use a Combo Box and Validation Logic to Restrict Form Opening

This method forces users to select an existing material and uses a background query check to ensure related records exist before the second form is allowed to open.

By restricting user input with a combo box, you prevent invalid or misspelled entries. Combining this control with a VBA or macro validation check guarantees the secondary form only loads when actual related data exists, avoiding blank entries.

1
Add a Combo Box to the Main Form

On your primary form, insert a Combo Box control. Set its 'Row Source' property to pull material names directly from your master materials table rather than allowing free-text entry.

2
Enforce Valid Selections

Open the Property Sheet for the Combo Box, navigate to the Data tab, and set the 'Limit to List' property to 'Yes'. This stops users from typing in non-existent material names.

3
Create a Pre-Open Validation Check

In the 'On Click' event of your 'Open Form' command button, write a macro or VBA script to run a DCount or lookup query against the bill-of-materials table using the selected Combo Box value as the criteria.

4
Apply Conditional Logic

Configure your VBA code with an 'If' statement: if the DCount function returns a value greater than zero, execute the 'DoCmd.OpenForm' action to load the second form. If it returns zero, display a message box informing the user that no matching records exist and cancel the form open event.

Database Normalization: Regularly reviewing your relationship diagrams ensures that your forms respect the underlying table structures, making data validation checks much more reliable.
Free Microsoft Office alternative

Looking for a Lightweight Alternative for Data Management?

While Microsoft Access handles complex relational databases, many data tracking, billing, and inventory tasks can be efficiently managed using spreadsheets. WPS Office provides a lightweight, highly compatible alternative to Microsoft Office, allowing you to manage complex lists and data relationships completely free.

  1. 1. Download WPS Office: Visit the official WPS website to download and install the free WPS Office suite.
  2. 2. Open WPS Spreadsheet: Launch WPS Spreadsheet, which offers a familiar interface for managing data tables, inventory lists, and financial records.
  3. 3. Organize Your Data: Use features like Data Validation, VLOOKUP, and Pivot Tables to manage your bill-of-materials easily without needing a complex database structure.
Fully compatible with Microsoft Excel (.xlsx) formats for seamless data transition.Easily manage inventory and bill-of-materials using advanced spreadsheet lookup functions.Lightweight software design that runs smoothly on all devices.Free to use with a highly familiar user interface, requiring zero learning curve.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Access form open to a blank new record?

By default, if an Access form is filtered or linked to a record that does not currently exist in the underlying table, the application will open the form in 'Data Entry' mode, presenting a blank new record instead of an empty screen.

What is the best way to check if a record exists before opening a form in VBA?

You can use the 'DCount()' domain aggregate function in your VBA code. If DCount returns 0 based on your current form's criteria, you can use the 'MsgBox' function to alert the user and skip the 'DoCmd.OpenForm' command.

How do I stop users from typing invalid data into my form?

Replace standard text boxes with Combo Boxes linked directly to your primary tables. Ensure the 'Limit to List' property is set to 'Yes' so users can only select predefined, valid entries.