Link to home
Start Free TrialLog in
Avatar of kearley
kearley

asked on

ApplyFilter

I have a form in which all events call macros.  I am converting all of my macros to code since I need to create a runtime version of the app.
I have a double-click events of a Last Name control (and several others).  On the On DblClick event, the macro Applies a Filter using ApplyFilter in which a query is opened prompting for a last name to search.  After I click OK, the record(s) matching the criteria entered displays via my form.  If I click Cancel instead of OK when prompted for the Last Name to Search, the parameter box just disappears.  This works great with a macro.  When converting this macro to code, I use DoCmd.ApplyFilter "qrySearchForName" When I run this code and enter a last name to search when prompted and click OK, the record(s) matching my criteria are displayed.  The problem occurs when I click 'Cancel' at the parameter box.  I receive a runtime error '2501' indicating the ApplyFilter command was canceled.  How can I avoid getting this error?  All I want to do is cancel the filtering.  I would rather not include "On Error Resume Next" in my code.
ASKER CERTIFIED SOLUTION
Avatar of kulikuli
kulikuli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kearley
kearley

ASKER

Thanks....
PS. What I usually do, is create an error handler, like:
Exit_DoubleClick_Whatever:
exit sub

Err_DoubleClick_Whatever:
select case err
   case 2501
    'nothing happens
   case else
     msgbox"Error:" & err.number & vbcrlf & err.description
end select
resume Exit_DoubleClick_Whatever

Avatar of kearley

ASKER

Great. Thanks again.
Avatar of kearley

ASKER

Is there a more efficient way for me to apply the filters and search on certain data entered?  I have about 10 controls that have this double-click event going on.  Each one applies a separate filter prompting for search criteria.  I have used recordsets a little and am wondering if using a recordset may be a better option (if it is an option...).  Also, I have a "new" button which does a DoCmd.GoToRecord,,,acNewRec and it takes forever to clear the screen and go to a blank record.  I am not sure why! I only have 100 records in the underlying table!  Any suggestions are welcome.  Let me know if I'm suppose to open a new question and allocate new points....
Please open a new question for each problem and be very specific on what you want to do. You want to use filters, ok. But for what purpose? This is important for answering the question. I actually think that what you really want is not to use filters but change the form's recordset.... we'll see.