Filter Microsoft Access Records by ID Range Using a Form
Question details
Filter Access records by codes assigned according to the last three digits of an ID, with ranges that can be changed over time.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Users need a form control to select one or more workload codes while a supervisor maintains the underlying ID ranges.
- Observed behavior
- Records should display the code matching their last three ID digits and be filterable by the selected codes.
Identify the table and numeric field that contain the nine-digit IDs, and confirm that the form can use a query as its record source. Decide whether the range table should represent current assignments only, because changing a range will change the codes calculated for existing records.
Use a range lookup table and a multi-select form filter
Use this approach when supervisors need to adjust ranges without editing application code and users need to select multiple codes.
The query calculates each code from the current range table. Keep ranges inclusive and nonoverlapping so each possible suffix matches no more than one row.
The example assumes a numeric ID field named IDfield in a table named YourTable. Replace those names with your actual table and field names.
In Create > Table Design, create a table named tluIDCodes with a Short Text field named IDCode and Number fields named LowVal and HiVal. Add rows such as U1, 0, 399 and U2, 400, 599. Add any other ranges needed to cover the suffixes you use.
Open Create > Query Design, switch to SQL View, and enter: SELECT t.*, DLookup("IDCode", "tluIDCodes", "LowVal <= " & ([IDfield] Mod 1000) & " AND HiVal >= " & ([IDfield] Mod 1000)) AS AssignedCode FROM YourTable AS t WHERE t.IDfield Is Not Null; Save the query and set the form's Record Source property to it.
Open the form in Design View and add an unbound list box to the Form Header. Name it lstCodes, set Multi Select to Simple or Extended, and set its Row Source to: SELECT DISTINCT IDCode FROM tluIDCodes ORDER BY IDCode;
Add a button named cmdApplyFilter to the Form Header. In its On Click property, choose Event Procedure, click the builder button, and enter this code in the generated procedure: Dim item As Variant Dim codes As String For Each item In Me.lstCodes.ItemsSelected codes = codes & ",'" & Replace(Me.lstCodes.ItemData(item), "'", "''") & "'" Next item If Len(codes) > 0 Then Me.Filter = "[AssignedCode] IN (" & Mid(codes, 2) & ")" Me.FilterOn = True Else Me.FilterOn = False End If
Open the form in Form View, select one or more codes in lstCodes, and click cmdApplyFilter. To change assignments, edit the rows in tluIDCodes, then requery or reopen the form and its list box to see the updated results.

Review exported Access records in WPS Spreadsheet
WPS Office is a free, lightweight Office alternative with a familiar interface. Export Access records to a spreadsheet for a simple move into WPS Spreadsheet; WPS does not replace the Access database form or its VBA filter.

Frequently Asked Questions
How does Access get the last three digits of a numeric ID?
Use [IDfield] Mod 1000 in a query. For example, an ID ending in 007 returns the number 7, which can be matched against numeric range boundaries.
Can I select more than one code on the form?
Yes. Set the list box's Multi Select property to Simple or Extended, then use an Apply button to build a filter from its ItemsSelected collection.
How do I clear the code filter?
Clear all selections in the list box and click the Apply button. In the example, an empty selection sets the form's FilterOn property to False.
What happens when a supervisor changes a range?
The query uses the current rows in tluIDCodes, so existing records may receive different calculated codes after the form is requeried. Store a separate assignment history if past assignments must be preserved.
Why does an ID have no assigned code?
Check tluIDCodes for a gap in LowVal and HiVal and confirm that IDfield contains a valid numeric value. The example query excludes records where IDfield is null.




