473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Transferspreadsheet Trapping Error for Duplicate records

I have a procedure to automate bringing several Excel files into our
Access tables, on a daily basis.

The problem is that if the user has a problem, and tries to run the
import again (maybe 3 files imported then there was a data problem and
they want to re-import after fixing the problem), I can't get the Error
handling to fire if the user is attempting to import duplicate key
records.

Message when I try to import records already on the table. There are
17 records on the .xls.

Microsoft Access was unable to append all the data to the table

The contents in the fields of 0 record(s) were deleted, and 17
record(s) were lost due to key violations.

Here is my code. I've tried trapping error 3022, 10014, 10018 and none
of them works.

I looked on prior posts, but didn't see the same problem. Thank you
very much.
Sara

Sub ImportData()
On Error GoTo ImportData_Err

SaleDate = Me.getSaleDate
strMsg = "Nothing Imported"
'------------------------------------------------------------
' POS10A - Store Sales T:StoreSalesData
'------------------------------------------------------------

strStepErrorMsg = "POS10A"
strImportFileName = Format([SaleDate], "mm-dd-yy") & " POS10A" &
".xls"

' MsgBox strImportFileName

DoCmd.TransferSpreadsheet acImport, 8, "T:Store Sales Data", _
"\\server-03\Building19\ProductionImports\" & strImportFileName,
True, ""

strMsg = "POS10A imported"

' 9 other import files here - all basically the same format
'------------------------------------------------------------
' MDYYMMDD.xls - Spags Tax Data
'------------------------------------------------------------

strImportFileName = "TX" & Format([SaleDate], "yymmdd") & ".xls"

' MsgBox strImportFileName

DoCmd.TransferSpreadsheet acImport, 8, "tblSpagsTaxInfo", _
"\\server-03\Building19\ProductionImports\" &
strImportFileName, True, ""

strMsg = "Spags Tax, " & strMsg

Importdata_Exit:
Exit Sub

ImportData_Err:
If Err.Number = 10014 Then
' If the problem is duplicate key, tell the user what was already
imported
' and the query or table that had the problem (**??? tried error
3022?)
MsgBox "Data was imported for " & strMsg
MsgBox "The problem file or query is " & strStepErrorMsg
Else
If Err.Number = 10018 Then
' If the problem is duplicate key, tell the user what was already
imported
' and the query or table that had the problem
MsgBox "Data was imported for " & strMsg
MsgBox "The problem file or query is " & strStepErrorMsg

Else
' If the problem is not dup key, display the error information
MsgBox "Data was imported for " & strMsg
MsgBox "The problem file or query is " & strStepErrorMsg
MsgBox Err.Number & " " & Err.Description & "Please call
Sara with this info."
End If
End If

Resume Importdata_Exit

End Sub

Jan 10 '06 #1
6 8132
Red
I just want to reiterate my issues with the transferspreadsheet
method...

I hate using it, it's SO buggy.... and definately gives you errors (as
seen by Sara's problems with the above)

Now, Onto Sara...

There are two ways to 'error trap' this situation...

I will describe breifly how to do each..

1) Use the Transferspreadsheet methos to x-fer to a 'temp' table, and
then have a query add data that is not duplicated between the 2 tables

2) (The better way IMHO) Import progmatically, checking on each record.
Assuming you don't have thousands of lines in any of the spreadsheets,
it's really not a big deal to do it progrmatically...

I have started making a wiki on MrExcel.com on how to progmatically
transfer data to and from Excel/Access.. if you require more info, I
will point you in the right direction.

~Red

Jan 10 '06 #2
I appreciate the thoughts, but I am not that sophisticated, so I'd
rather do the error trapping if I could.

Anyone else have ideas?

Thanks

Jan 10 '06 #3
Change the error handler so that it will show you the error number that
occurs when the user tries to add duplicate records:

msgbox err.Number & " " & err.Description

Then you'll know what error is occuring so you can trap it.

Linda

"sara" <sa*******@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I appreciate the thoughts, but I am not that sophisticated, so I'd
rather do the error trapping if I could.

Anyone else have ideas?

Thanks

Jan 10 '06 #4
I do display the Error Number. The message I put in the post comes up
BEFORE it gets to error handling, so there is no number. If I say "NO"
to the message, I get 2501 - the Transferspreadsheet was cancelled. If
I say "Yes" the code just moves on, which isn't what I want.

Any ideas? Anyone?

Thanks

Jan 11 '06 #5
Red
LMAO... I think I just got what you are trying to do... heh...

kinda anyhow....

To get rid of the annoying "The contents in the fields of 0 record(s)
were deleted, and 17
record(s) were lost due to key violations. " message, use the command
"DoCmd.Setwarnings = False"

However you said:
If I say "NO"
to the message, I get 2501 - the Transferspreadsheet was cancelled. If
I say "Yes" the code just moves on, which isn't what I want.


So, what exactly DO you want it do after the message?

~Red

Jan 11 '06 #6
I have been setting warnings to False (and then true later). However,
IF the user tries to import a day she already imported or (more likely)
corrected some data and wanted to import the NEW data, the message that
tells her there is already data for that date on the table is
suppressed, due to False.

I want to be able to trab the message that there are duplicate keys and
tell the user. The manager could then evaluate: Delete the "old"
records that they were trying to correct, or whatever.

We get our data emailed to us from a 3rd party every day, and, on
occasion, we have these problems. I just can't get the code to NOT
suppress that message - so I can deal with it myself.

Is this more clear? Any ideas?

Thank you -
Sara

Jan 11 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
4
by: Doo-Dah Man | last post by:
I hope this is the right group for this question, if it's not please direct me. I have a data-driven website that allows users to enter records for sales leads. It all works perfectly. The...
0
by: Frances | last post by:
Hi All, I'm having a problem trying to add a record to a simple Access 2000 db (db is very similar to an address book but with more info than the usual address, phone, etc.). The database is...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
3
by: user_5701 | last post by:
Hello, I'm getting an error with a Docmd.Transferspreadsheet line of code: DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel2000, "tblTest", pathAndFilename, True The above line...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
0
by: robert.waters | last post by:
Hello, When executing DoCmd.TransferSpreadsheet to an .xls file that's being used as a datasource for a Word mail merge document, if that Word document is currently open, the TransferSpreadsheet...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.