On Thursday, March 27, 2014 6:12:40 PM UTC-5, croy wrote:
> On Thu, 27 Mar 2014 12:05:55 -0700 (PDT), Patrick Finucane <
patrickf...@gmail.com> wrote: >On Thursday, March 27, 2014 1:47:54 PM UTC-5, croy wrote: >> I hava a form with some footer fields used to filter the form. The form's underlying query has criteria that point to those footer fields. Also in the footer section are buttons for "Apply filter" and "Remove Filter". The Apply Filter button simply invokes requery. The Remove Filter button clears all the footer filter fields, and then requerys. It's working well, except... If someone chooses a combination of criteria that results in no records, the detail section comes up blank, which is fine. But when the "Remove Filter" button (custom) is clicked, an error message appears: "No current record" (OK or Help), and I can't figure out how to trap it. So I'm wondering if there's a way to have my own message appear if the filter results in no records, much the way a report will do, and abort the code before the Requery happens. I've seen some things on the web about cancelling the opening of a form if there would be no records, but nothing about aborting the filer on the same form. -- >Any help appreciated. croy > >I typically use an alternative to your method. Ex: > Me.form.Filter = "CustomerID = " & 1 > ME.Form.FilterOn = True Thanks for that. I wish I was good enough with code to do that for my two cbos (who and where), txtboxes for beginning date and ending date, and the "notes" field. I've made it work in the query, but getting the syntax correct in code is just beyond me. >I don't get your error messages. I'm assuming you mean that with your way, the message doesn't appear, rather than you don't understand my error message.... ;0 -- croy
I might have a command button with the caption Set Filter. In the OnClick event I then do something like
Dim strF As String
IF Not IsNull(Me.ComboBox1Name) then
strF = "Field1NameToFilter = " & Me.ComboBox1Name
Endif
IF Not IsNull(Me.ComboBox2Name) then
If strF > "" then strF = strF & " And "
strF = strF & "Field2NameToFilter = " & Me.ComboBox2Name
Endif
Me.Filter = strF 'might be Me.Form.Filter
Me.FilterOn = (strF > "") 'might be Me.Form.FilterOn
All you need to do is replace the combo box names and field names to filter