Others

Detect New Query Records with VBA in Access 2016

Camila MilosovichCamila Milosovich Nov 25, 2026 869 views

Question details

Detect when new records match an Access form's query and run an action only when new results appear.

Detect New Query Records with VBA in Access 2016
Product
Microsoft Access 2016
Device & OS
Windows 10, selected in the original submission
Scenario
A form periodically requeries its record source to check for records that meet specific criteria.
Observed behavior
The form should trigger a function when the refreshed query contains new matching records.
Before you start

Confirm that the form is bound to the query whose results you want to monitor and that records can only be added to its result set. Choose a timer interval that gives the database enough time to complete each requery.

Solution 1Recommended

Compare form record counts in the Timer event

Use this approach when matching records can be added but cannot disappear from the query results.

The Timer event counts the form's current records, requeries the form, and counts the refreshed records. MoveLast ensures that RecordCount reflects all records in each nonempty clone.

1
Set the timer interval

Open the form in Design View, select the form, and open its Property Sheet. On the Event tab, set Timer Interval to a value in milliseconds, such as 60000 for one minute.

2
Create the event procedure

In the Property Sheet, set On Timer to [Event Procedure], then click the build button (...) to open the VBA editor.

3
Add the comparison code

Replace the generated Form_Timer procedure with the following code. Add both procedures to the form's VBA module: Private Sub Form_Timer() Dim beforeCount As Long Dim afterCount As Long beforeCount = FormRecordCount() Me.Requery afterCount = FormRecordCount() If afterCount > beforeCount Then HandleNewRecords End If End Sub Private Function FormRecordCount() As Long Dim rs As DAO.Recordset Set rs = Me.RecordsetClone If Not (rs.BOF And rs.EOF) Then rs.MoveLast FormRecordCount = rs.RecordCount Else FormRecordCount = 0 End If rs.Close Set rs = Nothing End Function Private Sub HandleNewRecords() ' Add the action to run when new records appear. End Sub

4
Add and test your action

In HandleNewRecords, add the code or function call you want to run. Save the form, open it in Form View, and add a record that meets the query criteria to test the next timer event.

Compare form record counts in the Timer event
When records can disappear: A count comparison can miss a new record if another record disappears between checks. In that case, store and compare the unique record keys before and after each requery.
Free Microsoft Office alternative

Work with Office documents in 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 easy to move existing files. It does not replace Access forms or run their VBA timer events.

Review exported query data in WPS SpreadsheetsOpen and edit Microsoft Office formats such as XLSX, DOCX, and PPTXUse a familiar interface for everyday office workMove existing Office documents into a lightweight, easy-to-use suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does the code use MoveLast before RecordCount?

For a nonempty RecordsetClone, MoveLast forces Access to visit the last record so RecordCount reflects the full result set. The code checks for an empty recordset first to avoid calling MoveLast on it.

How often will the form check for new records?

The form checks at the interval specified by Timer Interval on the Property Sheet's Event tab. The value is in milliseconds; 60000 means one minute.

What if records can be removed as well as added?

Compare unique record keys rather than only counts. Store the keys from the form's current recordset, requery, and check the refreshed keys for any that were not in the stored set.

Where do I put the function I want to run?

Add your action or a call to your existing function inside the HandleNewRecords procedure in the form's VBA module. It runs only when the refreshed count is greater than the previous count.

Does requerying preserve the current record?

A form requery can change the current record. If users need to stay on the same record, save its unique key before Me.Requery and locate that key afterward.