[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 453
  • Last Modified:

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.
0
kearley
Asked:
kearley
  • 3
  • 3
1 Solution
 
kulikuliCommented:
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
 
kearleyAuthor Commented:
Thanks....
0
 
kulikuliCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kearleyAuthor Commented:
Great. Thanks again.
0
 
kearleyAuthor Commented:
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
 
kulikuliCommented:
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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now