Access 2000: ApplyFilter action canceled

Greetings,

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!
perstamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tomk120999Commented:
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 & "#"
Else
   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...
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomk120999Commented:
Sorry, the above assumes you have 2 controls named StartDate and EndDate on the form.
0
perstamAuthor Commented:
Tom,

This worked great!  Thanks for your help.

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

Sam
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.