Updating an indexed table from XML file - stopped in duplicate values - How to bypass (1 Viewer)

JDB

Registered User.
Local time
Today, 09:02
Joined
Mar 10, 2013
Messages
13
Good afternoon from sunny Calif

Using VBA I am reading data in from multiple XML files, and adding data to an indexed table.

If I try to add a duplicate record I get a error like:
"The changes you requested to the table were not successful because they would create duplicate values in the index, primary key or relationship <snip>" and the data reading procedure stops.

How do I skip adding those records and just continue on reading the next XML record or file.

Thanks

JDB
 

MarkK

bit cruncher
Local time
Today, 09:02
Joined
Mar 17, 2004
Messages
8,180
Hello there and welcome to the forum.

Search Access VBA help for "Elements of Run-Time Error Handling." There is an excellent article about how to handle errors in VBA.
 

JDB

Registered User.
Local time
Today, 09:02
Joined
Mar 10, 2013
Messages
13
Thanks - Did some reading and did some and this seems to work

Sub Something
On Error Resume Next

...code to read XML and call an Update subroutine .....

End sub
 

MarkK

bit cruncher
Local time
Today, 09:02
Joined
Mar 17, 2004
Messages
8,180
Be careful using just On Error Resume Next. There is a time and place for that, but if your code fails for different and/or unexpected reasons, you'll have no indication that the failure mode has changed from the one you programmed for. In that case rows may not get added that should have been, and you'll never know, and that error is sometimes more damaging, the one you that happens that you never catch. The article I refer to says this ...
You can use the On Error Resume Next statement if you want to check the properties of the Err object immediately after a line at which you anticipate an error will occur, and handle the error within the procedure rather than in an error handler.
If you never check what error occurs you may unwittingly be sweeping some very severe problems "under the rug."
 

Users who are viewing this thread

Top Bottom