Solved

ApplyFilter

Posted on 1998-10-15
6
442 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 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