Solved

ApplyFilter

Posted on 1998-10-15
6
445 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
kulikuli earned 100 total points
ID: 1965439
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
ID: 1965440
Thanks....
0
 
LVL 5

Expert Comment

by:kulikuli
ID: 1965441
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:kearley
ID: 1965442
Great. Thanks again.
0
 

Author Comment

by:kearley
ID: 1965443
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
ID: 1965444
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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