Others

Fix a DateAdd Syntax Error in an Access DLookup Expression

Adam DavisAdam Davis Nov 22, 2026 869 views

Question details

Calculate the previous day from a form control and use it in an Access DLookup criterion.

Fix a DateAdd Syntax Error in an Access DLookup Expression
Product
Microsoft Access
Device & OS
not provided
Scenario
A form expression looks up balance in t_daily_balance using the date in Text37 minus one day.
Observed behavior
A direct date comparison works, but adding DateAdd causes an invalid syntax error. Some suggested expressions avoid the error but leave report fields blank.
Before you start

Confirm that Text37 contains a valid date and that tdate is a Date/Time field in t_daily_balance. Check whether tdate includes time values and whether the expression runs on the form or on a report.

Solution 1Recommended

Concatenate the calculated date into the DLookup criteria

Use this expression when tdate contains dates without time values.

The third DLookup argument must be a criteria string. Calculate the date outside the quoted string, then concatenate it between Access date delimiters.

1
Open the expression

Open the form in Design View, select the control that displays the balance, and find its Control Source in the Property Sheet.

2
Enter the corrected expression

Replace the Control Source with: =DLookUp("[balance]","[t_daily_balance]","[tdate]=#" & Format(DateAdd("d",-1,[Text37]),"mm\/dd\/yyyy") & "#")

3
Test the lookup

Open the form in Form View, enter a valid date in Text37, and check whether t_daily_balance contains a matching tdate for the previous day.

Concatenate the calculated date into the DLookup criteria
Check the control reference: If the expression runs on a report while Text37 is on an open form, replace [Text37] with Forms![FormName]![Text37], using the actual form name. The exact-date comparison will not match a tdate with a non-midnight time.
Free Microsoft Office alternative

Work with exported Access data in WPS Spreadsheets

WPS Office is a free, lightweight alternative with a familiar interface for spreadsheet work. Export Access data to Excel format to continue working with it in WPS Spreadsheets; WPS does not repair Access DLookup expressions.

Review and analyze exported date and balance data in a spreadsheetOpen and edit Microsoft Excel XLSX and XLS filesUse a familiar interface for a smoother move from Office spreadsheetsAccess a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does Access treat Text37 as literal text?

If [Text37] is inside the quoted criteria string, it is not evaluated as the form control's value. Place DateAdd outside the string and concatenate its result into the criteria.

Why is the DLookup result blank after the syntax error is fixed?

DLookup returns Null when no record matches. Check the date in Text37, the previous day's records in t_daily_balance, and whether tdate includes a time. Use the date-range expression if it does.

How do I reference Text37 from a report?

If Text37 is on an open form, use Forms![FormName]![Text37] in place of [Text37] in the report expression. Replace FormName with the actual form name.

What if Text37 is empty or does not contain a valid date?

Enter a valid date in Text37 before evaluating the expression. DateAdd and DateValue require a usable date value, so an empty or invalid control can prevent the lookup from working.

Why format the date in the criteria string?

Access date literals are enclosed in # delimiters. Formatting the calculated date as mm/dd/yyyy makes the value passed into the criteria explicit and helps avoid regional date-format ambiguity.