• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 919
  • Last Modified:

Access 2000: ApplyFilter action canceled


Well, I'm having another filter problem ...

I'm trying a docmd.applyfilter to a form based on user input to that same form.  I've coded the applyfilter in the afterupdate event of a control on the form so that after then user enters the data the filter is executed.  Unfortuantely, I get run time error 2501:  applyfilter action canceled.  I guess I'm not understanding something here, but I thought I could do this kind of thing.

Anyone have any ideas?

Thanks in advance!
  • 2
1 Solution
Hi, perstam.  Here's the VBA code to do what you want.  Some of it is "abbreviated", so you will have to read between *some* lines:

First set up the Filter string (it must be a string).  It might go something like this: (Note, you probably want to check for data in a control before you try to append it to the filter string)

strFilter = "Date >= #" & Me!StartDate & "#"

If Len(strFilter > 0 Then
   strFilter = strFilter & "AND Date <= #" & Me!EndDate & "#"
   strFilter = "Date <= #" & Me.EndDate & "#"
End If

Then you just have to apply the filter and *turn it on*:

Me.Filter = strFilter
Me.FilterOn = True

You can do this in a button click event, the AfterUpdate event of a control, or ...

Make sure you have the property for the form set to accept filters, which is the default.  I think it's Can Have Filter (check the properties dialog to be sure).

You can also set the Me.OrderBy property in VBA to sort the filtered records:

Me.OrderBy = "Date"

HTH, good luck as usual...
Sorry, the above assumes you have 2 controls named StartDate and EndDate on the form.
perstamAuthor Commented:

This worked great!  Thanks for your help.

I'll get back with you on the other one tomorrow ...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now