Filter Form doesn't close

C

CP

Hi all. I have an Access 2007 form with a command button that does
this on the OnClick event:

DoCmd.RunCommand acCmdAdvFilterSort

The filtering form opens correctly and I'm able to specify my
criteria. If I right click and choose Apply Filter/Sort, the
filtering works BUT the filter form doesn't close. Instead, my Access
2007 form appears in front of it and gets the focus but the filtering
form stays open.

I'm using a customized ribbon and have tried two other ways to
accomplish this. The first is:

idMso = "ApplyFilter"

The second is a macro that runs a function with this code:

DoCmd.RunCommand acCmdApplyFilterSort
DoCmd.Close acForm, "frmQueryDesignFilter1"

(frmQueryDesignFilter1 = the name of my form + "Filter1" and it's what
I see at the top of the filtering form).

These don't close the filtering form either.

(Note: Another option I thought about was using DoCmd.ApplyFilter
"xxxx" where "xxxx" is the where clause to use when filtering. But
since users will specify their own criteria so the where clause
constantly changes, I haven't been able to figure out how to use it.
Don't know if that makes any difference....)

In Access 2003, I used this command to get into the filtering:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 0, 2,
acMenuVer70

and this one to do the filtering, close the filter form, and return to
my own form:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 2, ,
acMenuVer70

These did the trick in Access 2003 (even though they were out-of-date)
but obviously they don't work in Access 2007.

Filtering works correctly (and the filtering form closes as it should)
when I'm in Access 2007 using a plain vanilla database and form but
something must be differrent in my customized application. Hopefully
someone can point me in the right direction.

Thanks in advance. Carol.
 
B

Barry A&P

You could just hide the form

forms!frmQueryDesignFilter1.visible = False 'then apply the filter
DoCmd.RunCommand acCmdAdvFilterSort

Barry
 
C

CP

Thanks, Barry, but I was totally going down the wrong path. I just
figured out that frmQueryDesignFilter1 wasn't a FORM, it was a QUERY
(given the name because it is temporarily created from the form
frmQueryDesign.).

When I changed my code to:

DoCmd.RunCommand acCmdApplyFilterSort
DoCmd.Close acQuery, "frmQueryDesignFilter1"


The filtering was done and the "filtering form" closed. Hooray!

Thanks again. Carol.
 

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