Solved

ApplyFilter

Posted on 1998-10-15
6
430 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:kearley
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
kulikuli earned 100 total points
Comment Utility
I'm sorry, but the correct solution is what you already pointed out: On error resume next, or On error goto Exit_DoubleClick_Whatever

This is because the docmd object is still a macro derived object to emulate macro commands.

Best regards,

kulikuli
0
 

Author Comment

by:kearley
Comment Utility
Thanks....
0
 
LVL 5

Expert Comment

by:kulikuli
Comment Utility
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

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:kearley
Comment Utility
Great. Thanks again.
0
 

Author Comment

by:kearley
Comment Utility
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....
0
 
LVL 5

Expert Comment

by:kulikuli
Comment Utility
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.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now