Me.FilterOn problem - Access 2007

F

FPS, Romney

I've been using various filter buttons and drop-down boxes in Access 97 and
2000/2002 to filter records on forms. These forms could be closed and when
reopened would no longer be filtered, which was what was desired. In Access
2007, however, the forms would reopen with the last filter which had been
used. For example, if the form had been closed when filtered for names
beginning with "M", the next time the form opened it would still be filtered
to "M".

So, I added code to the Load event for the form:
If Me.FilterOn Then
Me.FilterOn False
End If

This works fine if opening the form from the main menu. However, some of
these forms are also opened from other forms and are intended to open
filtered for the same client as the first form. Now, of course, they
don't -- because of the code in the OnLoad event of this second form.

I hope this description makes sense. I'm wondering if there's some option in
Access 2007 which would allow the forms and filters to work just like they
did in previous versions -- i.e., ignore whatever filter had been applied
the last time the form was closed.
I guess I could stipulate in the OnLoad event code to only turn the filter
off if the form is being opened by the main menu. (Not exactly sure how to
do that).
Better yet, I could put the code in the OnClose event which should not
interfere with opening the form filtered to some other form when that is
what is wanted.

Thanks for any advice.
Mark
 
E

ErezM via AccessMonster.com

hi Mark
i'm not sure about the specifics of access 2007, but to your other question
(how to determine the form was opened from the main menu and not by code), a
solution could be:
when you open the form from code, use the OpenArgs argument of the OpenForm
command to send some value (whatever)
then during the Form Load Or Open events, check for Me.OpenArgs's value
forms opened directly by the user cannot have this argument set

hope that helps
 
F

FPS, Romney

Thanks ErezM for the suggestion. Putting the code in the OnClose event seems
to be working. That way, when it's opened via the main menu it'll open
without any filter applied -- as intended -- and when it's opened via
another form a filter *can* be applied -- and not be cancelled by the form's
OnLoad event.
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top