Others

Count Records in a Microsoft Access DAO Recordset

Ayan MasoodAyan Masood Nov 27, 2026 868 views

Question details

Determine whether an Access table contains records before processing them with DAO.

How to Count Records in a Microsoft Access DAO Recordset
Product
Microsoft Access
Device & OS
not provided
Scenario
A VBA procedure needs to check a local temporary table or a linked table before processing its records.
Observed behavior
The user wants to identify an empty table and choose whether to open or process a recordset.
Before you start

Confirm whether the table is local or linked in the Access Navigation Pane, and replace the example table name with your own. Open the VBA editor with Alt+F11 and check Tools > References for a Microsoft Office Access database engine or DAO library if DAO types are not recognized.

Solution 1Recommended

Check a Local Table with DAO TableDef.RecordCount

Use this approach to check a local table before opening its recordset.

1
Open the VBA editor

In Access, press Alt+F11 and open the module containing your table-processing procedure.

2
Check the table count

Add this code to your procedure, replacing t_ExcelExport_auto with your local table name: Dim db As DAO.Database Dim rst As DAO.Recordset Set db = CurrentDb If db.TableDefs("t_ExcelExport_auto").RecordCount = 0 Then ' Handle the empty table Else Set rst = db.OpenRecordset("t_ExcelExport_auto") ' Process the recordset, then close it rst.Close End If

3
Run the procedure

Run the procedure from Access or press F5 in the VBA editor, and verify that the appropriate empty-table or processing branch runs.

Check a Local Table with DAO TableDef.RecordCount
Use this for local tables: A linked table's TableDef.RecordCount does not provide a reliable count. Use a recordset or DCount for linked tables instead.
Free Microsoft Office alternative

Work with Exported Access Data in WPS Office

WPS Office is a free, lightweight, easy-to-use alternative for everyday Office work. Export Access data to an Excel workbook, then use WPS Spreadsheets' familiar interface to review it; compatible Office formats make migration straightforward.

Review and count exported table rows in WPS SpreadsheetsCompatible with Microsoft Excel XLSX and XLS filesFamiliar spreadsheet interface for an easy transitionFree and lightweight for everyday document work
microsoft office alternative - wps office

Frequently Asked Questions

How can I tell whether an Access recordset is empty?

After opening the recordset with CurrentDb.OpenRecordset, check rst.EOF. If it is True immediately after opening, the recordset contains no records.

Why is my DAO RecordCount lower than the total number of rows?

For a dynaset or snapshot, RecordCount reflects records accessed so far. If the recordset is nonempty and supports moving backward, call rst.MoveLast before reading rst.RecordCount.

Can I use TableDef.RecordCount for a linked table?

Do not rely on TableDef.RecordCount for a linked table. Open a DAO recordset and check EOF, or use DCount with the linked table name.

How do I count only records that meet a condition?

Use the criteria argument of DCount, for example DCount("*", "t_ExcelExport_auto", "[Status] = 'Ready'"). The criteria syntax is similar to a SQL WHERE clause without the word WHERE.