Access to Excel export

lloyd2002

New Member
Joined
Feb 8, 2016
Messages
11
I'm trying to export tables to Excel using the following code:-



Private Sub Command0_Click()
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Light", "W:\STOCK AVAILABILITY\Iveco Stock Availability.xls", True, "Light"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Medium", "W:\STOCK AVAILABILITY\Iveco Stock Availability.xls", True, "Medium"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Heavy", "W:\STOCK AVAILABILITY\Iveco Stock Availability.xls", True, "Heavy"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Driveaway", "W:\STOCK AVAILABILITY\Iveco Stock Availability.xls", True, "Driveaway"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Platinum", "W:\STOCK AVAILABILITY\Iveco Stock Availability.xls", True, "Platinum"
End Sub


The code creates the file, but I get an error message saying the data is corrupt. The files size for the excel file is also very small considering the amount of data I'm trying to export.

Any ideas?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi Joe,

Thanks for the advice, I changed the extension, but still receive the same problem.

The file size is 32KB, whereas with the amount of data I would have expected it to be a few hundred. And I receive an error when I try to open that states "the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

I also tried changing the type to 12Xlm as I'm using Excel 2010 with xlsx extension, but still the same issue.
 
Upvote 0
Why are you populating the last argument for named range? I believe that is only for Imports (there are not named ranges in Access).

Try this for the first one:
Code:
[COLOR=#333333]DoCmd.TransferSpreadsheet acExport, 10, "Light", "W:\STOCK AVAILABILITY\Iveco Stock Availability.xlsx", True, ""
[/COLOR]

Here is a little trick I used. Get one working in a Macro first, and then use "Convert your Macros to Visual Basic" to get the syntax you need to apply.
 
Last edited:
Upvote 0
You are most welcome!:)
 
Upvote 0

Forum statistics

Threads
1,221,828
Messages
6,162,215
Members
451,752
Latest member
freddocp

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top