Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-15-2019, 01:13 PM   #1
Danick
Newly Registered User
 
Join Date: Sep 2008
Posts: 255
Thanks: 41
Thanked 2 Times in 2 Posts
Danick is on a distinguished road
Filtered form gets run-time error 2001 on "Esc"

I have a continuous form that I'm using with various filters. There is a command button to filter the form based on what the user selects in a few combo boxes. The "Apply Filter" command button is the default so when the user presses "Enter" on the keyboard, the form gets filtered. There is also a "Cancel filter - show all records" button.

If the user starts to enter data in the filter boxes but presses "Esc" before applying the filter, then the form undoes the entries and resets to unfiltered. That's fine. But if the user presses the "Esc" button after the form is filtered (either by pressing "Enter" or pressing the "Apply Filter" button, then Access produces a run-time error 2001 (You canceled the previous operation).

How can I trap this error for Access to disregard it or to mimic the "Cancel Filter" button if the user presses "Esc".

Danick is offline   Reply With Quote
Old 04-15-2019, 01:17 PM   #2
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 8,876
Thanks: 105
Thanked 2,379 Times in 2,186 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: Filtered form gets run-time error 2001 on "Esc"

In the error handling section try
Code:
if err=2001 Then Resume Next
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 04-15-2019, 01:22 PM   #3
Danick
Newly Registered User
 
Join Date: Sep 2008
Posts: 255
Thanks: 41
Thanked 2 Times in 2 Posts
Danick is on a distinguished road
Re: Filtered form gets run-time error 2001 on "Esc"

Quote:
Originally Posted by isladogs View Post
In the error handling section try
Code:
if err=2001 Then Resume Next
Where do I put this error handling? I tried putting it in the form On Current event, but still getting the error.

Danick is offline   Reply With Quote
Old 04-15-2019, 01:30 PM   #4
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 8,876
Thanks: 105
Thanked 2,379 Times in 2,186 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: Filtered form gets run-time error 2001 on "Esc"

You could try the Form_Error event but I've never had this issue in my apps so I can't say that with real confidence
Otherwise, you need to step through the code and determine where it is triggered.
From your description, possibly in two places??
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 04-15-2019, 01:35 PM   #5
Danick
Newly Registered User
 
Join Date: Sep 2008
Posts: 255
Thanks: 41
Thanked 2 Times in 2 Posts
Danick is on a distinguished road
Re: Filtered form gets run-time error 2001 on "Esc"

Quote:
Originally Posted by isladogs View Post
You could try the Form_Error event but I've never had this issue in my apps so I can't say that with real confidence
Otherwise, you need to step through the code and determine where it is triggered.
From your description, possibly in two places??
Well Form_Error event didn't work either.

I believe that Access has the "Escape" keyboard button built in so that it always tries to perform a "Cancel / Undo" event. So there isn't anywhere in my code that is triggering it.
Danick is offline   Reply With Quote
Old 04-15-2019, 02:51 PM   #6
Danick
Newly Registered User
 
Join Date: Sep 2008
Posts: 255
Thanks: 41
Thanked 2 Times in 2 Posts
Danick is on a distinguished road
Re: Filtered form gets run-time error 2001 on "Esc"

Well after a little google searching, I found a way of doing this using the KeyDown event. solution found here:
Code:
http://www.vbforums.com/showthread.php?367165-VB6-Using-the-KeyDown-Event
For anyone interested, here is how you do it.

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'make sure KeyPreview is True on Form Properties
    On Error Resume Next
    Select Case KeyCode
        Case vbKeyEscape 

            'add you code here.  I added my cancel event VBA to mimic pressing the "View All Records" button.  


    End Select
End Sub
Seems to be working for me...
Danick is offline   Reply With Quote
Old 04-16-2019, 01:39 AM   #7
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 8,876
Thanks: 105
Thanked 2,379 Times in 2,186 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: Filtered form gets run-time error 2001 on "Esc"

Ironically, I was also going to suggest using the KeyDown event to block the use of Enter or Esc in this case. Adapting your posted code below

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'make sure KeyPreview is True on Form Properties
    On Error Resume Next
    Select Case KeyCode
        Case vbKeyEscape, vbKeyReturn
            'don't allow use of Esc / Enter
             KeyCode=0
        
    End Select
End Sub


__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"you can't save this record at this time" error on empty form! shwan Forms 6 11-19-2017 11:09 AM
error 2001 "You canceled the previous operation" jocelyn_ooi Modules & VBA 6 09-28-2011 07:49 PM
SQL error. "runtime error '2001' you cancelled the previous operation" bobmac- Modules & VBA 7 04-27-2010 06:09 PM
D-look did work before, but it is now "RUN TIME ERROR 2001" suddendly! 1308057 Modules & VBA 3 07-30-2008 05:39 AM
Error 2001: "You cancelled the previous operation" R2D2 Modules & VBA 6 04-17-2003 04:54 AM




All times are GMT -8. The time now is 10:43 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World