Others

Replace Multiple DLookup Calls with a Recordset in Microsoft Access

Rana GarciaRana Garcia Nov 27, 2026 868 views

Question details

Retrieve several fields from the same Access record without running a separate DLookup call for each field.

Replace Multiple DLookup Calls with a Recordset in Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
Access code or a form needs multiple values from a table using the same matching criteria.
Observed behavior
Repeated DLookup calls search the same table multiple times.
Before you start

Identify the table, fields, and criteria used by the existing DLookup calls. For the VBA solution, check that the Microsoft Office Access database engine object library is available under Tools > References in the VBA editor.

Solution 1Recommended

Read multiple fields from a parameterized DAO recordset

Use this approach when VBA code needs several values from the same matching record.

A parameterized query supplies the criteria once and returns all selected fields in one recordset. If the criteria can match multiple records, define how to select the intended record rather than relying on an unspecified first match.

1
Open the VBA editor

In Access, press Alt+F11, then open the module or event procedure that contains the DLookup calls.

2
Open a parameterized recordset

Replace the example table, field names, parameter type, and value with your own. For example, use the following code for a numeric CustomerID: Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim rs As DAO.Recordset Set db = CurrentDb Set qdf = db.CreateQueryDef("", _ "PARAMETERS [pID] Long; " & _ "SELECT [CompanyName], [City] FROM [Customers] " & _ "WHERE [CustomerID] = [pID];") qdf.Parameters("pID").Value = 123 Set rs = qdf.OpenRecordset(dbOpenSnapshot)

3
Read the fields and close the recordset

Check for a match before reading the fields, then release the objects. For example: If Not rs.EOF Then Debug.Print Nz(rs.Fields("CompanyName").Value, "") Debug.Print Nz(rs.Fields("City").Value, "") Else Debug.Print "No matching customer" End If rs.Close Set rs = Nothing Set qdf = Nothing Set db = Nothing

4
Test the result

Run the procedure with a known ID and view the output in the VBA editor's Immediate window with Ctrl+G. Also test an ID with no match.

Read multiple fields from a parameterized DAO recordset
Match the parameter to your data: The example uses a Long parameter for a numeric ID. Declare a suitable parameter type for your actual criteria, and replace the Debug.Print statements with the assignments your procedure needs.
Free Microsoft Office alternative

Work with exported Access data in WPS Spreadsheets

WPS Office is a free, lightweight alternative for everyday office work, with a familiar interface and support for Microsoft Office formats. Export Access data to Excel to work with it in WPS; WPS does not replace Access databases, DAO, or forms.

Review and analyze Access data exported to an Excel spreadsheet.Open and edit Microsoft Excel XLSX and XLS files.Use a familiar spreadsheet interface for everyday tasks.Move compatible Office documents into a lightweight suite.
microsoft office alternative - wps office

Frequently Asked Questions

Why use a recordset instead of several DLookup calls?

A query can return all the required fields in one result, avoiding repeated domain-function searches. Open it as a DAO recordset when VBA needs to read the values.

What happens if the query finds no matching record?

Check rs.EOF before reading rs.Fields. If EOF is True immediately after opening the recordset, handle the missing match instead of attempting to read field values.

How do I display the values without writing VBA?

Create and test a query with the required fields and criteria, then set a form or report's Record Source property to that query and bind its controls to the fields.

Can WPS Office run an Access DAO recordset?

No. DAO recordsets and Access forms require Microsoft Access. You can export query results from Access to an Excel file and open that file in WPS Spreadsheets.