Fix DLookup #Error for Empty Fields in Microsoft Access
Question details
The user needs to prevent a Microsoft Access DLookup expression from returning #Error when the criteria field is empty or null.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A user has a DLookup expression in a Microsoft Access form or report and the criteria field can be left blank.
- Observed behavior
- The calculated control displays #Error when the criteria field is blank or null.
Open the database object in Design view and identify the control containing the DLookup expression. Confirm whether the criteria field uses text or numeric data so you can choose the correct Nz replacement value.
Use Nz in the DLookup criteria expression to handle empty fields
Use this solution when the DLookup criteria field can be empty or null, and the expression currently returns #Error.
DLookup builds a SQL WHERE condition. If the criteria field is Null, the string concatenation can create an invalid expression, so Access displays #Error. Wrapping the field reference in Nz supplies a non-null default value and keeps the expression valid.
In Microsoft Access, right-click the form or report that contains the DLookup expression and select Design View.
Click the text box or calculated control that shows #Error, then open the Property Sheet.
In the Control Source property, update the DLookup criteria using Nz, for example: =DLookup("[LCS]","[LowestClassScore]","Subject=" & Nz([Forms]![Result Extended]![Subject],0)).
If Subject is text, use Nz([Forms]![Result Extended]![Subject],"") and build the criteria as "Subject='" & Nz([Forms]![Result Extended]![Subject],"") & "'"; if it is numeric, use 0.
Save the form, switch to Form View, and clear the Subject field to confirm that the calculated control no longer displays #Error.

Use WPS Office Free as a Lightweight Microsoft Office Alternative
Because WPS Office does not include Microsoft Access or a DLookup function, this Microsoft Access expression issue must be corrected inside Access. For everyday documents, spreadsheets, and presentations, WPS Office is a free, lightweight alternative with full compatibility for Word, Excel, and PowerPoint files and a familiar ribbon interface.
- 1. Download the free installer: Go to the official WPS Office website and click Download WPS Office Free.
- 2. Install and launch WPS Office: Run the installer, complete the setup, and open WPS Office from the desktop or Start menu.
- 3. Open your existing files: Click Open in the WPS Office home screen and choose a .docx, .xlsx, or .pptx file to continue working.

Frequently Asked Questions
Why does DLookup return #Error when a criteria field is empty?
When the criteria field is Null, Access concatenates an invalid WHERE condition such as Subject=. Wrapping the field reference in Nz supplies a valid default value and prevents the error.
What Nz replacement value should I use in a DLookup text criteria?
Use an empty string with Nz and include quotes in the criteria string, for example: "Subject='" & Nz([Forms]![Result Extended]![Subject],"") & "'".
Can Nz be used with multiple DLookup criteria fields?
Yes, wrap each nullable field reference in Nz separately and choose a replacement value that matches each field's data type.
Does WPS Office support Microsoft Access DLookup expressions?
No, WPS Office does not include Microsoft Access or the DLookup function. This expression must be corrected in Microsoft Access; WPS Office is an alternative for Word, Excel, and PowerPoint files.
How do I test a DLookup expression after adding Nz?
Save the form or report, switch to Form View or Report View, and leave the criteria field blank to confirm the calculated control no longer displays #Error.




