Filter a Microsoft Access Form by a Lookup Field ID
Question details
Filter a Microsoft Access form using the numeric ID stored by a lookup or combo box rather than its displayed text.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A user selects a lookup value in a combo box and wants the form to display records with the matching numeric ID.
- Observed behavior
- The desired result is a form filtered by the selected ID, with defined behavior when the combo box is empty.
Open the form in Design View and confirm that its record source includes the numeric field you want to filter. Check that the combo box's Bound Column returns the ID; the examples use tSpecCode as the numeric field and luCode as the combo box.
Apply a numeric ID filter in the combo box's After Update event
Use this approach to filter the form after a selection and treat an empty combo box as ID zero.
A combo box can display descriptive text while returning a numeric ID from its bound column. Nz does not select that column or convert text to an ID; it only replaces a Null value with the fallback value you supply.
In Design View, select luCode and open the Property Sheet. On the Data tab, check Row Source and Bound Column. Set Bound Column to the column containing the numeric ID; column numbering starts at 1. On the Format tab, use Column Widths to hide the ID column if you want only descriptive text displayed.
With luCode selected, open the Event tab in the Property Sheet. Set After Update to [Event Procedure], click the Build (...) button, and choose Code Builder if prompted. Use the combo box's After Update event, not the form's Current event, for filtering after a selection.
Inside the generated luCode_AfterUpdate procedure, enter: Me.Filter = "tSpecCode = " & Nz(Me.luCode, 0) Me.FilterOn = True Replace tSpecCode and luCode with your actual field and control names. Because the field is numeric, do not surround the ID with quotation marks in the filter expression.
Save the form, switch to Form View, and select a value in luCode. The form should display records whose tSpecCode matches the selected ID. Clear the combo box to verify that the filter becomes tSpecCode = 0.

Show all records when the lookup combo box is cleared
Use an explicit Null check when an empty selection should restore the full record list.
Use WPS Office to review Access data exported to spreadsheets
WPS Office is a free, lightweight alternative for working with spreadsheet exports and related documents, with a familiar interface and Microsoft Office format compatibility for an easy transition. It does not replace Microsoft Access or run Access forms and VBA event procedures; apply the form filter in Access, then export the results for review in WPS Spreadsheet.

Frequently Asked Questions
Does Nz make the combo box return its unique ID instead of the displayed text?
No. Nz only replaces Null with a specified value, such as zero. In Design View, select the combo box and check Property Sheet > Data > Bound Column to control which column supplies its value.
Should the filter code go in the form's Current event?
For filtering after a user selects a combo box value, place the code in the combo box's After Update event. Select the control in Design View, then open Property Sheet > Event > After Update > Build (...). The form's Current event runs when the current record changes and is not the appropriate trigger for this selection-based filter.
Why does setting Me.Filter not change the displayed records?
Assigning Me.Filter defines the filter expression but does not necessarily enable it. Add Me.FilterOn = True after setting the expression, and confirm that the field name exists in the form's record source.
Can I use the lookup ID in a macro Where Condition?
Yes. For an action with a Where Condition argument, such as OpenForm, use an expression such as "tSpecCode = " & Nz([Forms]![fAccList]![luCode], 0). The source form fAccList must be open, and luCode must return a numeric ID. An empty control produces a condition for ID zero, not a request to show all records.
Can WPS Office run this Access form filter?
No. WPS Office does not run Access database forms or their VBA event procedures. Configure the filter in Microsoft Access. To review the resulting data in WPS Spreadsheet, use Access's External Data > Export > Excel command and open the exported workbook in WPS.




