[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

How do I suppress the message "...can't append all the records in the append query"

I would like the error message (see attached) to not appear whenever this situation occurs. How can I suppress it? I have already inserted the DoCmd.Set Warnings False but it is still appearing.
Append-Warning.jpg
0
geeta_m9
Asked:
geeta_m9
  • 2
2 Solutions
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Use this code instead to run your action queries :

CurrentDB.Execute "YourActionQueryName", dbFailOnError

Best approach ... and no warning messages, but will show any error that may occur and that you will want to know about.

mx
0
 
GrahamMandenoCommented:
Using the Execute method with dbFailOnError will allow you to trap the error and suppress the message or take some other action, but it will also prevent your query from appending any records at all.  It will have the equivalent effect to clicking "No" in the screenshot you posted.

You should modify your query so that it does not attempt to append records for key fields that already exist.

For example, say your query is as follows:

INSERT INTO Table2 (KeyField, OtherField)
SELECT DISTINCT Field1, Field2 FROM Table1;


This will fail if Field1 in Table1 contains a value that already exists in KeyField in Table2.

To avoid this, add a WHERE clause to select records with values that do NOT exist in a subquery:

INSERT INTO Table2 (KeyField, OtherField)
SELECT DISTINCT Field1, Field2 FROM Table1
WHERE NOT EXISTS( SELECT * FROM Table2 WHERE KeyField=Table1.Field1 );


Then you can use the Execute method and it will not fail.

Best wishes,
Graham Mandeno [Access MVP 1996-2013]
0
 
geeta_m9Author Commented:
Graham Mandeno, your solution works great...exactly as you said it would.

I do not get the error anymore.

Thank you.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"but it will also prevent your query from appending any records at all"

Personally, I see this as a good thing, especially if I am *expecting* the query to append (etc) all records. I would rather know if it does not, and find out why.

On the other hand, if you are expecting that some records will not get appended, then you can use the SQL that Graham suggested, or trap for that specific error and ignore it.

In all cases,  you need to include error trapping in conjunction with the dbFailOnError.

mx [Access MVP 2009-2013)
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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