Others

Filter a Microsoft Access Main Form Using Linked Subform Data

Kushani NimanthikaKushani Nimanthika Nov 25, 2026 868 views

Question details

Filter an Access main form to show parent records with matching entries in a linked subform or related table.

Filter a Microsoft Access Main Form Using Linked Subform Data
Product
Microsoft Access
Device & OS
not provided
Scenario
A user selects a value, such as a contact or product, and wants the main form to show every parent record associated with it.
Observed behavior
The desired result is a filtered main form containing only parent records with matching related entries.
Before you start

Identify the main form's parent ID field, the related table's parent and selection ID fields, and the selection control's name. The example assumes ProjectID and ContactID are numeric fields and that the combo box returns ContactID as its bound value.

Solution 1Recommended

Filter the main form with an IN subquery

Use the selection control's After Update event to show projects associated with the selected contact.

The subquery finds matching parent IDs in the related table. The main form must include ProjectID in its record source; replace the example field, table, and control names with those in your database.

1
Check the selection control

Open the main form in Design View and select the combo box. In its Property Sheet, confirm that its name is cboContact and its bound column returns the numeric ContactID.

2
Open the event procedure

In the combo box's Property Sheet, select the Event tab. Set After Update to [Event Procedure], then select the ellipsis button to open the VBA editor.

3
Add the main-form filter

In the cboContact_AfterUpdate procedure, use this code: Private Sub cboContact_AfterUpdate() Dim selectedID As Variant selectedID = Me.cboContact.Value If IsNull(selectedID) Then Me.FilterOn = False Exit Sub End If If Not IsNumeric(selectedID) Then Me.FilterOn = False MsgBox "Select a valid contact ID." Exit Sub End If Me.Filter = "ProjectID IN (SELECT ProjectID FROM ContactProjects WHERE ContactID = " & CLng(selectedID) & ")" Me.FilterOn = True If Me.RecordsetClone.EOF Then MsgBox "No matching projects were found." End If End Sub

4
Test the filter

Save the form, switch to Form View, and select a contact in cboContact. Confirm that the main form shows matching projects; clear the combo box and move focus away to turn the filter off.

5
Optionally filter the subform

To show only the selected contact's entries in the subform, add these lines after Me.FilterOn = True: Me.fsubContacts.Form.Filter = "ContactID = " & CLng(selectedID) Me.fsubContacts.Form.FilterOn = True Replace fsubContacts with the subform control name. Also add Me.fsubContacts.Form.FilterOn = False before each Exit Sub so the subform filter is cleared when the selection is empty or invalid.

Filter the main form with an IN subquery
Filtering the subform is separate: A subform filter limits the related entries displayed within the current parent record; by itself, it does not filter the main form. The example expects a numeric Long-compatible ID, not a text ID.
Free Microsoft Office alternative

Work with Related Data in WPS Spreadsheets

WPS Office is a free, lightweight alternative for everyday documents and spreadsheets, with a familiar interface and Microsoft Office format support for easier migration. Use WPS Spreadsheets to filter tabular data; it does not run or fix Microsoft Access forms.

Filter spreadsheet rows to review matching data.Open and edit Microsoft Excel XLSX files.Use a familiar interface for common office tasks.Work with a free, lightweight office suite.
QA img-9

Frequently Asked Questions

Why does filtering the subform not filter the main form?

The subform's Filter property affects its own records. Set the main form's Filter property to an IN subquery against the related table and set Me.FilterOn to True to restrict parent records.

How do I show all main-form records again?

Clear the selection in the combo box and move focus away. The example's After Update event sets Me.FilterOn to False when the selection is null.

What if my combo box displays a name instead of an ID?

In Design View, check the combo box's Bound Column property. It can display a name while returning ContactID as its bound value; the example requires that returned value to be numeric.

Can I use a different related table or parent ID?

Yes. Replace ContactProjects, ProjectID, and ContactID in the filter expression with your table and field names. The outer parent ID must be available in the main form's record source.