I would like to capture a NO user response from the “CAN’T APPEND RECORDS…RUN QUERY?” (I paraphrase) error that ACCESS gives when an append query output violates the destination table validation rules. I Know I have seen (and at times captured) a 3059 OPERATION CANCELLED BY USER pop-up but now that I have the code written I can’t trigger the error. Is there some property that must be set to capture this response? Thanks.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Trapping ‘Operation Cancelled’ during Append Query (2000)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Trapping ‘Operation Cancelled’ during Append Query (2000)
- This topic has 6 replies, 3 voices, and was last updated 21 years, 1 month ago.
AuthorTopicWSBillHumphries
AskWoody LoungerApril 9, 2004 at 3:42 am #403468Viewing 3 reply threadsAuthorReplies-
WSMarkD
AskWoody LoungerApril 9, 2004 at 3:01 pm #812601If you’re referring to the error msg like the one illustrated, AFAIK this type of error cannot be trapped. See this MSKB article:
ACC2000: Cannot Trap Import Errors in Visual Basic for Applications
Article states in part: “The same rules that apply to manual data entry also apply to methods for importing data when using Visual Basic for Applications. Therefore, any violations of rules, such as referential integrity, validation rules, or the Required property, will result in an incomplete import. In Microsoft Access 2000, no trappable error is generated and if the procedure disables system messages by using the SetWarnings statement, there is no indication that any problem occurred. ” Though not exactly same situation, the same principle is applicable to running action queries, whether in UI or via VBA using DoCmd methods, you cannot trap this type of error.
When appending, updating, or deleting records programatically the recommended approach is to use the ADO Connection Execute method, or DAO equivalent. Both the ADO Connection object and the DAO Database & QueryDef objects have a RecordsAffected property that can be used to determine how many records were affected by the query. In addition, both the ADO Connection object and DAO DBEngine object have an Errors collection that you can loop thru to determine what specific error(s) occurred when trying to execute the query or SQL statement. The DAO errors tend to be more useful; when an ADO action query fails to execute due to key violations, etc, you usually get this standard error msg:
Invalid SQL statement; expected ‘DELETE’, ‘INSERT’, ‘PROCEDURE’, ‘SELECT’, or ‘UPDATE’.
As noted in MSKB article, disabling standard warnings with SetWarnings method is NOT a good idea, you have no way of determining if action query succeeded, failed, or only partially succeeded. Recommend use ADO or DAO Execute method for append, update, and delete queries, with appropriate error handling enabled.
HTH
-
WSBillHumphries
AskWoody LoungerApril 14, 2004 at 2:38 am #814312Thanks for your response. I got the following technique for executing an action query to work exactly as desired (I wrapped the code in a boolean function) as shown below. A couple of notes:
1)Using Docmd.openquery with a NO response to the “violations detected – continue?” dialog DOES sometimes raise a 3059 ‘user cancelled operation’ error and I remember at least once being able to trap it. Don’t know under what circumstances however and couldn’t reproduce it.
2) Controls on forms coded for query criteria did not seem to work using this technique. I had to code a parameter and build its value in VBA, as shown below.
3) DBFAILONERROR option is required or error will not be trapped.
4)Gratifyingly, the ERROR object returns exactly what error took place (ie what column failed).
:‘Calling code:
Set Qdf = CurrentDb.QueryDefs(“qryEstA_Cost_100A”)
Qdf.Parameters(“ctlsub”) = Me.ctlSub
If Not fDaoQry(Qdf) Then Exit FunctionFunction:
Function fDaoQry(Qdf As DAO.QueryDef) As Boolean
””””””””””””””””””””””””
Dim ErrNum, ErrDsc
”””””””””
On Error Resume Next
Qdf.Execute dbFailOnError
ErrNum = Err
ErrDsc = Err.Description
On Error GoTo 0
”””””””’
If ErrNum 0 Then
MsgBox “Error ” & ErrNum & ” executing ” & Qdf.Name & “: ” & ErrDsc, vbCritical
End If
””””’
fDaoQry = (ErrNum = 0)
End Function
;comments. -
WSBillHumphries
AskWoody LoungerApril 14, 2004 at 2:38 am #814313Thanks for your response. I got the following technique for executing an action query to work exactly as desired (I wrapped the code in a boolean function) as shown below. A couple of notes:
1)Using Docmd.openquery with a NO response to the “violations detected – continue?” dialog DOES sometimes raise a 3059 ‘user cancelled operation’ error and I remember at least once being able to trap it. Don’t know under what circumstances however and couldn’t reproduce it.
2) Controls on forms coded for query criteria did not seem to work using this technique. I had to code a parameter and build its value in VBA, as shown below.
3) DBFAILONERROR option is required or error will not be trapped.
4)Gratifyingly, the ERROR object returns exactly what error took place (ie what column failed).
:‘Calling code:
Set Qdf = CurrentDb.QueryDefs(“qryEstA_Cost_100A”)
Qdf.Parameters(“ctlsub”) = Me.ctlSub
If Not fDaoQry(Qdf) Then Exit FunctionFunction:
Function fDaoQry(Qdf As DAO.QueryDef) As Boolean
””””””””””””””””””””””””
Dim ErrNum, ErrDsc
”””””””””
On Error Resume Next
Qdf.Execute dbFailOnError
ErrNum = Err
ErrDsc = Err.Description
On Error GoTo 0
”””””””’
If ErrNum 0 Then
MsgBox “Error ” & ErrNum & ” executing ” & Qdf.Name & “: ” & ErrDsc, vbCritical
End If
””””’
fDaoQry = (ErrNum = 0)
End Function
;comments.
-
-
WSMarkD
AskWoody LoungerApril 9, 2004 at 3:01 pm #812602If you’re referring to the error msg like the one illustrated, AFAIK this type of error cannot be trapped. See this MSKB article:
ACC2000: Cannot Trap Import Errors in Visual Basic for Applications
Article states in part: “The same rules that apply to manual data entry also apply to methods for importing data when using Visual Basic for Applications. Therefore, any violations of rules, such as referential integrity, validation rules, or the Required property, will result in an incomplete import. In Microsoft Access 2000, no trappable error is generated and if the procedure disables system messages by using the SetWarnings statement, there is no indication that any problem occurred. ” Though not exactly same situation, the same principle is applicable to running action queries, whether in UI or via VBA using DoCmd methods, you cannot trap this type of error.
When appending, updating, or deleting records programatically the recommended approach is to use the ADO Connection Execute method, or DAO equivalent. Both the ADO Connection object and the DAO Database & QueryDef objects have a RecordsAffected property that can be used to determine how many records were affected by the query. In addition, both the ADO Connection object and DAO DBEngine object have an Errors collection that you can loop thru to determine what specific error(s) occurred when trying to execute the query or SQL statement. The DAO errors tend to be more useful; when an ADO action query fails to execute due to key violations, etc, you usually get this standard error msg:
Invalid SQL statement; expected ‘DELETE’, ‘INSERT’, ‘PROCEDURE’, ‘SELECT’, or ‘UPDATE’.
As noted in MSKB article, disabling standard warnings with SetWarnings method is NOT a good idea, you have no way of determining if action query succeeded, failed, or only partially succeeded. Recommend use ADO or DAO Execute method for append, update, and delete queries, with appropriate error handling enabled.
HTH
-
WBell
AskWoody_MVPApril 10, 2004 at 7:49 pm #812983Adding to Mark’s comments, there is a partial work-around for import errors. When an import error occurs, in most circumstances Access creates an “Import Errors” table, and writes records that describes the problem to that table. If you are automating an import process, you can check for the existance of that table, and if it exists, you can then warn the user. That doesn’t solve all the problems, but it does provide some help.
-
WBell
AskWoody_MVPApril 10, 2004 at 7:49 pm #812984Adding to Mark’s comments, there is a partial work-around for import errors. When an import error occurs, in most circumstances Access creates an “Import Errors” table, and writes records that describes the problem to that table. If you are automating an import process, you can check for the existance of that table, and if it exists, you can then warn the user. That doesn’t solve all the problems, but it does provide some help.
Viewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
How well does your browser block trackers?
by
n0ads
53 minutes ago -
You can’t handle me
by
Susan Bradley
3 hours, 6 minutes ago -
Chrome Can Now Change Your Weak Passwords for You
by
Alex5723
1 hour, 4 minutes ago -
Microsoft: Over 394,000 Windows PCs infected by Lumma malware, affects Chrome..
by
Alex5723
8 hours, 27 minutes ago -
Signal vs Microsoft’s Recall ; By Default, Signal Doesn’t Recall
by
Alex5723
8 hours, 39 minutes ago -
Internet Archive : This is where all of The Internet is stored
by
Alex5723
8 hours, 51 minutes ago -
iPhone 7 Plus and the iPhone 8 on Vantage list
by
Alex5723
8 hours, 56 minutes ago -
Lumma malware takedown
by
EyesOnWindows
16 hours, 10 minutes ago -
“kill switches” found in Chinese made power inverters
by
Alex5723
17 hours, 44 minutes ago -
Windows 11 – InControl vs pausing Windows updates
by
Kathy Stevens
17 hours, 38 minutes ago -
Meet Gemini in Chrome
by
Alex5723
21 hours, 44 minutes ago -
DuckDuckGo’s Duck.ai added GPT-4o mini
by
Alex5723
21 hours, 52 minutes ago -
Trump signs Take It Down Act
by
Alex5723
1 day, 5 hours ago -
Do you have a maintenance window?
by
Susan Bradley
17 hours ago -
Freshly discovered bug in OpenPGP.js undermines whole point of encrypted comms
by
Nibbled To Death By Ducks
8 hours, 3 minutes ago -
Cox Communications and Charter Communications to merge
by
not so anon
1 day, 9 hours ago -
Help with WD usb driver on Windows 11
by
Tex265
1 day, 14 hours ago -
hibernate activation
by
e_belmont
1 day, 18 hours ago -
Red Hat Enterprise Linux 10 with AI assistant
by
Alex5723
1 day, 21 hours ago -
Windows 11 Insider Preview build 26200.5603 released to DEV
by
joep517
2 days ago -
Windows 11 Insider Preview build 26120.4151 (24H2) released to BETA
by
joep517
2 days, 1 hour ago -
Fixing Windows 24H2 failed KB5058411 install
by
Alex5723
21 hours, 4 minutes ago -
Out of band for Windows 10
by
Susan Bradley
2 days, 5 hours ago -
Giving UniGetUi a test run.
by
RetiredGeek
2 days, 12 hours ago -
Windows 11 Insider Preview Build 26100.4188 (24H2) released to Release Preview
by
joep517
2 days, 20 hours ago -
Microsoft is now putting quantum encryption in Windows builds
by
Alex5723
16 hours, 4 minutes ago -
Auto Time Zone Adjustment
by
wadeer
3 days ago -
To download Win 11 Pro 23H2 ISO.
by
Eddieloh
2 days, 22 hours ago -
Manage your browsing experience with Edge
by
Mary Branscombe
3 hours, 28 minutes ago -
Fewer vulnerabilities, larger updates
by
Susan Bradley
34 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.