Access (from Office 2016) saving output as worksheet limited to 65,536 rows

Err

Active Member
Joined
Nov 16, 2006
Messages
274
Hi,

I'm using the following VBA command to save my query results to an Excel file:

Code:
DoCmd.OutputTo acOutputQuery, "My_Query_Results", "Excel Workbook (*.xlsx)", "C:\Query_Results\My_Query_Results.xlsx", False, "", 1, acExportQualityScreen

When the results are over 65,536 rows then it only saves the top 65,536 and worse -the file seems corrupted when Excel VBA attempts to open it. Excel VBA doesn't have a problem opening this file when the initial Access results are less than 65536 rows.

In both cases, (Excel and Access) the version is 2016 and ought to be able to handle these number of rows.

Thanks.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I see too possible problem with that number of row.

The first is the extension of your Excel, as you save it in xlsx, but shouldn't be a problem.

The second is a possible integer type. Integer have a limit of 65536. You might to verify what kind of data you have in your Access table.

Edit, not sure of my number for Integer ...
 
Last edited:
Upvote 0
I don't see "Excel Workbook (*.xlsx)" as being a valid argument for output format anywhere in documentation. Try instead: acFormatXLSX

Code:
DoCmd.OutputTo acOutputQuery, "My_Query_Results", acFormatXLSX, "C:\Query_Results\My_Query_Results.xlsx", False, "", 1, acExportQualityScreen

I can't really vouch for the other optional arguments either. Unless you have a particular reason for including them I'd prefer:
Code:
DoCmd.OutputTo acOutputQuery, "My_Query_Results", acFormatXLSX, "C:\Query_Results\My_Query_Results.xlsx"
 
Upvote 0
Hi,

Thanks for your help.

Unfortunately, I tried this with 646, 361 rows and it still made a Worksheet, stopping at 65,536 rows:

I took a screen shot but the img tags aren't working anymore:

http://i.imgur.com/3TT054Q.png
 
Upvote 0
What exactly did you try?

Code:
DoCmd.OutputTo acOutputQuery, "My_Query_Results", acFormatXLSX, "C:\Query_Results\My_Query_Results.xlsx"



The script passes a TSQL string to the server and opens a datasheet:

Code:
DoCmd.OpenQuery "My_Query_Results", acViewNormal, acReadOnly

In this case the query that returns 73,217 rows

http://i.imgur.com/ih04GzA.png

When I open the file that it's trying to save it only saves 65535 rows

http://i.imgur.com/7VXpSbo.png

I can verify the KEY in the source table:

http://i.imgur.com/O0x6mxK.png


A google search yields that I am not the only one with this problem. Another board suggested using

Code:
DoCmd.TransferSpreadsheet

instead.
 
Upvote 0
The script passes a TSQL string to the server

What does this mean? What script?

Post all relevant information!
 
Upvote 0
What does this mean? What script?

Post all relevant information!

Here's the relevant code that fixed the problem:

Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "My_Query_Results", "C:\Query_Results\My_Query_Results.xlsx", 1
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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