Others

Filter Microsoft Access Records by ID Range Using a Form

Olivia MillerOlivia Miller Nov 25, 2026 868 views

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.

Filter Microsoft Access Records by ID Range Using a Form
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.
Before you start

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.

Solution 1Recommended

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.

1
Create the range table

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.

2
Create the record query

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.

3
Add a code selector

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;

4
Add an apply button

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

5
Test and maintain the ranges

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.

Use a range lookup table and a multi-select form filter
Range boundaries matter: LowVal and HiVal are inclusive: a suffix of 399 matches 0–399, while 400 matches 400–599. Gaps return no code, and overlapping ranges can produce an unpredictable match.
Free Microsoft Office alternative

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.

Filter exported ID and code columns in WPS SpreadsheetCompatible with Microsoft Excel formats such as XLSXFamiliar spreadsheet interface for reviewing exported dataFree and lightweight for everyday document work
QA img-9

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.