Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Error Goto errorhandler

Status
Not open for further replies.

foreveryoung

Programmer
Sep 24, 2002
45
GB
Just a little problem here. Consider the following

on error goto errorhandler

docmd.openquery "thequeryname"
docmd.openquery "thequeryname1"
docmd.openquery "thequeryname2"

leave:
exit sub

errorhandler:
msgbox "Error Occured"
resume leave

ok when the code reaches docmd.openquery "thequeryname1" and I know there is a key violation on running this append query I want the code to jump to errorhandler. Instead I am getting the large message saying 0 records were not copied due to unique index etc I am sure you are aware of this message.

Anyone know how to get to the errorhandler in this situation?

Thanks
David
 
I don't believe that situation is a trappable error. See trappable error list in ACCESS Help.

You can however look for the Key Violations prior to running the Append Query. Simply make another query with an inner join on the key fields and perform a DCount. If the result is greater than 0 then you have a Key Violation in the making. You can then use that perform a routine to flag and remove these records prior to running the append query.

Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top