Fix a DateAdd Syntax Error in an Access DLookup Expression
Question details
Calculate the previous day from a form control and use it in an Access DLookup criterion.

- 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.
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.
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.
Open the form in Design View, select the control that displays the balance, and find its Control Source in the Property Sheet.
Replace the Control Source with: =DLookUp("[balance]","[t_daily_balance]","[tdate]=#" & Format(DateAdd("d",-1,[Text37]),"mm\/dd\/yyyy") & "#")
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.

Use a date range when tdate includes a time
Use a range to find a record on the previous calendar day regardless of its time.
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.

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.




