gettign rid of filter

iankerry

Registered User.
Local time
Today, 07:46
Joined
Aug 10, 2005
Messages
190
hi

i have a form with a button on that launches a report - labels for mailing out.

any filter on the form is used to filter the report. it does this by the on open event on the report

Me.Filter = Forms![promoters].Filter
Me.FilterOn = True

this works ok.

but when i close the form and the report, the next time i use the report, it remembers the previous filter, regardless of any new filter i have on the form, and i cant get rid of it.

does any one know what i might be doing wrong?

thanks

ian
 
i think use the Close event of the report:
Me.Filter = ""
Me.FilterOn = False
something like that? (haven't used filter very much)
(or maybe clearing the filter before applying a new filter (On Open))
 
Re: getting rid of filter

Hi Wazz

Thanks for replying. I tried that but it seems to have no effect. when i run the report, from the form, with no filters, it still prints out the previous filter.

i investigated further and i'll see if i can explain clearly.

if i go to promoter form and filter for one persons name (smith). then click the labels button, one label is shown as being printed.

go out of database, goto promoter form, with all records showing, click on labels button, only smith label is printed.

i added your code to the report, no effect so i wondered where it was getting the filter from.

weirdly, even though there is no filter on the form, when you go into design mode, and look at the data - filter property is says promotername = smith.

why is the form remembering a previous filter? i have added your code in several places but i can't seem to get rid of it!

HELLPPP
 
When you want no Filter change your command to:

docmd.OpenReport "Your Report",acViewPreview,""

The filter = "".

Simon
 
try what simon says. (ahem).

also, from vba help:
"Filters are saved with the objects in which they are created. They are automatically loaded when the object is opened, but they aren't automatically applied...You can remove a filter by clicking the pressed-in Apply Filter button, clicking Remove Filter/Sort on the Records menu, or using Visual Basic to set the FilterOn property to False."

i remember having the same problem you're having (probably why i don't use filters much). don't remember what i came up with apart from deleting it from the form in design view and starting again. there must be a simple explanation, just not sure right now.

anyone shed light on this filter business? gotta split now. 7am. time for bed.
 
I've seen this with OrderBy as this became concatenated with alternating OrderBys. I suspect that what happens is the current OrderBy was removed but no all preceding OrderBys, it seems there is assumption that the OrderBy should already be blank. Removed the Orderby - Save Form yes - bye-bye multiple OrderBys.

Make any sense?

Simon
 
When you want no Filter change your command to:

docmd.OpenReport "Your Report",acViewPreview,""

The filter = "".

Simon

Thanks fopr replying Simon. The problem is that each time i run the labels i want it to forget any previous filter and take its filter from whatever is currently on the form. so i rarely want no filter.

cheers

ian
 
Re: getting rid of filter

You can remove a filter by clicking the pressed-in Apply Filter button, clicking Remove Filter/Sort on the Records menu, or using Visual Basic to set the FilterOn property to False."

i remember having the same problem you're having (probably why i don't use filters much). don't remember what i came up with apart from deleting it from the form in design view and starting again. there must be a simple explanation, just not sure right now.

Hi Wazz

This is really interesting.

Using the Advanced clear filter option before pressing the print report button does work - but of course by then (clicking the report button) the user has already setup a filter of labels to print.

so the next obvious thing to do is to put me.filter="" and me.filteron=false on the load event.

However, and this is where i have been chasing my own tail...

This promoter form, is sometimes called from another form. by clicking on the "goto promoter form" button on the summary form, it takes you to that precise record you were on. This no longer works of course if i have the me.filter="" on the onload event. do you follow?

is there an answer?

many thanks again.

ian
 
Re: getting rid of filter

I've seen this with OrderBy as this became concatenated with alternating OrderBys. I suspect that what happens is the current OrderBy was removed but no all preceding OrderBys, it seems there is assumption that the OrderBy should already be blank. Removed the Orderby - Save Form yes - bye-bye multiple OrderBys.

Make any sense?

Simon

Hi Simon,

i am not sure what connection is between orderby and a filter? But anyhow my orderby appear blank each time. have i missed your point? :-)

thanks
ian
 
Instead of using the filter approach on the report itself, why not declare the criteria before you even open the report. Assuming you have a button on your form that opens the report you could do something like this:

DoCmd.OpenReport stDocName, acPreview, , Me.Filter

This way you can make a decision using an if statement or etc. to decide whether the report needs to be filtered or not.

If you are determined to have the code remain in the Open Event to decide whether it needs to show all or not, you can make the decision before hand like with my code except pass in a variable under OpenArgs (Open Arguments). For example, pass in 1 or 0.

In your Open report procedure have the if statement "if 0 then me.filteron = false, else me.filteron = forms.etc"

Let me know if this helps, or I completely misunderstood your current situation.
 
Sorry for the double post, but I believe I see your problem.

On the form, the Filter is always saved with the form, however FilterOn is set to false whenever the form is opened by default. So even though your form appears to not be filtered (FilterOn is set to False), the Filter Property still has the last Filter that you used stored, and in return, your report automatically grabs it. Maybe you need a check to see if the previous form is really filtered before you decide to grab the filter criteria.

So here is an adaptation of your code that may work:

If Forms![promoters].FilterOn = True then
Me.Filter = Forms![promoters].Filter
Me.FilterOn = True
Else
Me.Filter = ""
Me.FilterOn = False
End if
 
Re: getting rid of filter

Hi Dev,

thanks for responding.

i really liked your solution. i added the me.filter to the openreport statement. however the form/report still remembered the filter from before.

if i go to sort&filter advanced clear filter then it does clear it and the report behaves as it should even when a new filter is applied.

i can't clear the filter programmatically when loading the form, as the form is loaded sometimes from another form, where is goes straight to a specific record. if i clear any filter using onopen, then i can't get it to go straight to a record from another form.

i am just looking at your next post to see if it clarifies things and will be back in touch. thanks hugely!

Ian
 
Re: getting rid of filter

you're the man. it worked a treat.

thanks so much for helping out. really appreciate the time and thought you have put into it.

best wishes

ian

p.s. thanks to the others too for trying!
:D
 
Glad it worked for you!

I learned something from this as well, I never realized that the filter property was saved, so good lesson learned.

Actually I have a current database where the Record Source changes to a different query depending on who is working with the database, I had to go back and recheck to make sure the Record Source wasn't saved with the form as well. Apparently it seems only the Filter is, which I find weird, but we got to the bottom of it.

Anyhow, I'm glad we were able to solve your problem. Good luck with the project!
 
Re: getting rid of filter



i love this forum!
 

Users who are viewing this thread

Back
Top Bottom