How to Avoid Circular References in Access Carryover Calculations
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.

- 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 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.
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.
Press ALT + F11 in Microsoft Access to open the Visual Basic for Applications (VBA) editor, and insert a new Module from the Insert menu.
Write a subroutine that declares a DAO.Recordset. Define variables to hold the 'TotalHours' and the 'PreviousCarryover' values.
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.

Utilize Temporary Tables for Iterative Processing
If you prefer not to use VBA, you can calculate the values using sequential queries that write the results into a temporary table, breaking the circular dependency.
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. Download and Install: Download WPS Office Free from the official website and install the suite on your device.
- 2. Import Your Data: Export your Access table as an Excel or CSV file, then open it seamlessly in WPS Spreadsheet.
- 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.

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.




