Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ApplyFilter to Form with no results causes problem

Status
Not open for further replies.

Bobot

MIS
Jan 11, 2002
52
US
OK guys - here's the scoop ---

I have a form showing all records. I have several unbound controls at the bottom accepting any combination of search criteria, for example FIRSTNAME and LASTNAME and STATE, etc. The user fills in any or all of the search fields and then hits a command button.

My command button then either does an ApplyFilter to the form or SetRecordSource to a generated SQL statement. Either way I get the same results, and surprising when there is data which meets criteria, it works great and the filtered records are displayed on the form correctly.

The problem is when there are no records that match the criteria. The form goes blank, almost disabled, and the navigation buttons go away and no records are shown. Any button or move I make after that gives me an error. The exact error does not appear to be really pertinent to this question, because depending on what button you press you will get a different error. What I mean is, the command click events still function but I have variables and focus and enables to reset which I cannot seem to do because I cannot catch the fact that there are no records to display *before* setting the filter on the form.

How the heck do you handle this. It works well now with that exception and I was hoping not to delve into recordsets at this point if I don't have to because I really don't understand them yet.

Any ideas are greatly appreciated.

- Bob
 
You have to evaluate whether or not records will be returned by your query, followed by if, then logic to either allow you to proceed or terminate the procedure.

DCount will allow you evaluate whether or not records will be returned:

RecordCount = Dcount("MyFieldName","qryMyQuery")

If RecordCount = 0 then your query will return no records and you can proceed accordingly. - - - -

Bry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top