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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem running import code

Status
Not open for further replies.

emik

MIS
Jul 24, 2006
80
CA
For this process, my program imports an Excel file into a table.

The steps are as follows:

-Delete everything from the table
-Import the new data.

I have all the error trapping but the problem I have is if the user selects the wrong Excel file, the code will delete everthing from the table and on the transfer give me the error.

The logic I'm using now (which is repetitiou) is

-Import the data
-Delete the data
-Import the data

the first import is just to see if it will generate an error.

Anyone have a better suggestion? Thanks.

The code to import and delete is below:

CurrentDb.Execute "DELETE * FROM TABLE;", dbFailOnError

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "TABLE", strFileName, True, "A:I"
 
A common way is to do the import into a temporary table, check and eventually update the temporary table, append the data from the temporary table to the final destination and then clear the temporary table.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I guess the best way to do this would be through an Append query right?
 
Yes, an append query from the checked temporary table.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top