Display a No Results Message for an Access Form Query
Question details
The user needs an Access form to display a matching summons record or a custom message when the entered number is not found.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A user searches for a summons number using a form based on a query.
- Observed behavior
- Matching summons data should appear when a number exists; otherwise, the user should see a summons-not-found message.
Identify the summons number field and check whether its data type is Short Text or Number. The example below assumes a Short Text field and a saved query without parameters that returns the records you want to search.
Search from an unbound form and display a message with VBA
Use a search button to check for a summons before opening a filtered results form.
An unbound form is not directly connected to a table or query. An unbound text box stores the user's search entry rather than writing it to a record.
This example searches a saved, non-parameter query named qrySummons and opens a results form named frmSummonsResults based on that same query. Replace these names and SummonsNumber with your actual query, form, and field names.
In the Navigation Pane, create or edit qrySummons so it returns the summons records without prompting for a parameter. Set frmSummonsResults's Record Source property to qrySummons and include the SummonsNumber field.
Select Create > Form Design and leave the form's Record Source empty. Add an unbound text box named txtSummons and a button named cmdSearch.
In Design View, select cmdSearch. On the Property Sheet's Event tab, set On Click to [Event Procedure], click the build button, and add this code inside the generated procedure: Dim summons As String Dim criteria As String summons = Trim(Nz(Me.txtSummons.Value, "")) If summons = "" Then MsgBox "Enter a summons number.", vbInformation Exit Sub End If criteria = "[SummonsNumber] = '" & Replace(summons, "'", "''") & "'" If DCount("*", "qrySummons", criteria) = 0 Then MsgBox "Summons not found. Check the number and try again.", vbInformation Else DoCmd.OpenForm "frmSummonsResults", , , criteria End If
Open the search form in Form View, enter an existing number in txtSummons, and click the search button. Close the results form before searching again, then test a nonexistent number and confirm that the message appears.

Review summons lists in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar interface for working with office files. Open compatible spreadsheets and use filters to review summons lists when migrating spreadsheet-based work; WPS does not replace or fix an Access database form.

Frequently Asked Questions
Does an Access form have an On No Data event?
The No Data event is available for reports, not forms. For a form search, use the search button's On Click event to check for a matching record and call MsgBox when none is found.
What is an unbound text box?
An unbound text box is not tied to a table or query field. In Form Design, add a text box and leave its Control Source property empty so users can enter a search value without changing a record.
Do I need a combo box for the summons search?
No. An unbound text box and search button are sufficient. A combo box is optional if you want users to select or type a number from a list.
Can I use the original parameter query with the example?
The example uses DCount against a saved query without parameters. Remove the parameter prompt from the query used by DCount and the results form, then let the button apply the summons criteria when it opens the form.




