TransferSpreadsheet Method (1 Viewer)

aziz rasul

Active member
Local time
Today, 15:45
Joined
Jun 26, 2000
Messages
1,935
I have two tables (let's call them Table1 & Table2) that I export to a particular part of the hard drive. Table1 is always populated, while Table2 can be populated or have no records.

Here's the problem.

When using DoCmd.TransferSpreadsheet for both tables, the export is successful when both tables are populated and overwrite the existing spreadsheets, if they exist, without any problems.

However if Table2 has no records AND the spreadsheet for this table already exists, an error occurs which effectively say's that the file already exists.

I can get around the problem by first counting the records in Table2 and only exporting if there is at least one record.

However I would like to know whether there is a different way of solving the problem.
 

John.Woody

Registered User.
Local time
Today, 15:45
Joined
Sep 10, 2001
Messages
354
I would do what you say and check to see if there are any records to export. Before transfer spreadsheet

if dir(Yourpath\Yourfile.xls) <> "" then Kill "Yourpath\Yourfile.xls
Docmd.transferspreadsheet

Make sure you only kill the file if you have data to replace it or you could be left with nothing!!

HTH
John
 

aziz rasul

Active member
Local time
Today, 15:45
Joined
Jun 26, 2000
Messages
1,935
Good idea John. Thanks.
 

Users who are viewing this thread

Top Bottom