Others

Fix a Missing Operator in a Microsoft Access DLookup Query

Algirdas JasaitisAlgirdas Jasaitis Nov 25, 2026 868 views

Question details

Fix a DLookup criteria expression that causes a missing operator error when comparing a text ID.

Fix a Missing Operator in a Microsoft Access DLookup Query
Product
Microsoft Access
Device & OS
not provided
Scenario
A VBA DLookup expression searches an Equipment table using an ID value that contains text.
Observed behavior
Access interprets an unquoted value such as Soldering System as part of the query expression and reports a missing operator.
Before you start

In Access, open the Equipment table in Design View and check the data type of the ID field. Also confirm that the value in rs!EquipmentType is the value you intend to compare with ID.

Solution 1Recommended

Quote and escape text criteria in DLookup

Use this approach when the ID field stores text, including values with spaces or apostrophes.

1
Open the VBA expression

Open the relevant module or form code in the VBA editor and locate the DLookup call that searches the Equipment table.

2
Update the criteria

Wrap the text value in single quotes and escape embedded apostrophes: DLookup("[EquipmentType]", "Equipment", "[ID]='" & Replace(rs!EquipmentType, "'", "''") & "'").

3
Test the lookup

Run the code with a matching ID such as Soldering System, then test a value containing an apostrophe. Confirm that DLookup returns the expected EquipmentType.

Quote and escape text criteria in DLookup
Check the source value: This example assumes rs!EquipmentType contains the text to match against Equipment.ID. Handle Null values before calling Replace, and use the correct recordset field if the ID value comes from elsewhere.
Free Microsoft Office alternative

Work with Office documents using WPS Office

WPS Office is a free, lightweight alternative for working with documents, spreadsheets, and presentations. Its familiar interface and Microsoft Office format compatibility make it easier to move everyday files. It does not fix Access VBA or replace an Access database.

Open and edit Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface for everyday Office tasksWork with tabular data in WPS SpreadsheetsUse a lightweight suite with a free option
microsoft office alternative - wps office

Frequently Asked Questions

Why does DLookup report a missing operator for a text value?

Access expects a text value in the criteria expression to be enclosed in quotes. Without them, a value such as Soldering System is parsed as part of the expression rather than as a text literal.

How do I handle an apostrophe in the lookup value?

When using single quotes around a text criterion, use Replace(value, "'", "''") to double any embedded apostrophes before concatenating the value into the DLookup criteria.

Should a numeric ID be enclosed in quotes?

No. If ID is a numeric field, validate the source value and concatenate it without text quotes, such as "[ID]=" & CLng(idValue) for a valid integer within the Long range.

What does DLookup return if no record matches?

DLookup returns Null when no record satisfies the criteria. Check the result with IsNull before using it, and verify that the source value matches the field being searched.