Preventing New Record When Searched Item Is Not Found - TechRepublic
Question
May 16, 2008 at 07:31 AM
mirajik

Preventing New Record When Searched Item Is Not Found

by mirajik . Updated 18 years, 2 months ago

I have an unbound form “SearchForm” for search purposes with one text box “txtSearch” and one command button. This form is used to search the “Products” table and if search item is found it is displayed in the “ProductsParticulars” form which is bound to the Products table. Ususally the user fills in the product ID in the text box on SearchForm and then click the search button. I am using the following code for the search button.

Dim strSearch As String
strSearch = “([ID] = “””& Me.txtSearch & “””)”
DoCmd.OpenForm “ProductsParticulars”
Forms!ProductsParticulars.Filter = strSearch
Forms!ProductsParticulars.FilterOn = True

The thing is; this code works fine as long as the searched item is found, if no product with the matching ID, the form opens in add record mode. I do not like this because it adds empty records in my database.

I wan a code which will prevent addition of new records when the searched item is not found, that is whenever access fails to get the searched record error message should be displayed. Anyone with the helping hand? Your assistance will be highly appreciated

This discussion is locked

All Comments