Others

How to Avoid Circular References in Access Carryover Calculations

Aamir Naveed AkramAamir Naveed Akram Oct 12, 2026 869 views

Question details

The user needs to calculate TotalHours and CarryoverHours for each ID sequentially, where the current carryover depends on the previous step's total, without triggering a circular reference error.

How to Avoid Circular References in Access Carryover Calculations
Product
Microsoft Access
Device & OS
not provided
Scenario
Attempting to calculate step-by-step carryover values using standard queries where the required carryover field does not inherently exist in the source table.
Observed behavior
Standard Access queries fail or create sequential dependency (circular reference) because they cannot recursively calculate previous carryover values that aren't stored in the source table.
Before you start

Before modifying your database structure, ensure you have a current backup and verify your source table to confirm exactly which fields are stored versus which need to be calculated on the fly.

Solution 1Recommended

Use a VBA Procedure for Step-by-Step Calculation

Because a standard Access query cannot recursively calculate a missing previous carryover value, using a VBA procedure allows you to iterate through records sequentially and calculate totals step-by-step.

A standard SQL query processes data in sets and struggles with row-by-row recursive dependencies when the field doesn't exist in the source table. VBA Recordsets solve this by processing one record at a time.

1
Open the VBA Editor

Press ALT + F11 in Microsoft Access to open the Visual Basic for Applications (VBA) editor, and insert a new Module from the Insert menu.

2
Declare a Recordset and Variables

Write a subroutine that declares a DAO.Recordset. Define variables to hold the 'TotalHours' and the 'PreviousCarryover' values.

3
Loop Through the Records

Open the recordset sorted by ID and Step. Use a Do While Not rs.EOF loop to iterate through the records. For each record, calculate the current Carryover based on the stored PreviousCarryover variable, update the record, and then store the new Carryover into the PreviousCarryover variable for the next loop iteration.

Use a VBA Procedure for Step-by-Step Calculation
Avoid Cumulative SUM(): Use only the immediately preceding step's carryover for your calculations rather than summing all prior steps, as summing can produce incorrect results if a previous carryover was reduced to zero.
Free Microsoft Office alternative

Need to Manage Data Without Complex Databases? Try WPS Office

While Microsoft Access is powerful for complex relational databases, many data tracking and sequential calculation tasks can be handled far more easily in WPS Spreadsheet. WPS Office offers a free, lightweight, and highly compatible alternative to Microsoft Office, allowing you to use simple formulas instead of complex VBA.

  1. 1. Download and Install: Download WPS Office Free from the official website and install the suite on your device.
  2. 2. Import Your Data: Export your Access table as an Excel or CSV file, then open it seamlessly in WPS Spreadsheet.
  3. 3. Apply Carryover Formulas: Use standard relative cell references (e.g., =B2+C1) to easily calculate carryover totals row by row without database-level circular dependencies.
Free and lightweight Microsoft Office alternativeFully compatible with Microsoft Excel formats (.xlsx, .xls, .csv)Easily handle sequential carryover calculations using direct cell referencesFamiliar user interface requires no complex SQL or VBA knowledge
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a circular reference error in my Access query?

This error occurs when a query calculation refers to itself, or when it tries to recursively reference a calculated field that isn't stored in the original source table, creating an infinite calculation loop.

Can I use the SUM() function to calculate previous carryover in Access?

You should generally avoid summing all previous steps if the business logic only requires the immediately preceding step's carryover. Summing all past records can produce incorrect results, especially when interim carryovers reduce to zero.

Do I have to use VBA for sequential dependencies in Access?

While VBA provides the most robust and controlled method for step-by-step row calculations, you can also use alternative methods like temporary tables or Data Macros to bypass query limitations.