Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help,

I want to export 6 million rows of access database into access.
I got a VBA code but it only exports 1 sheet (max 1048576 row).
I need to export to excel into multiple sheets is fine for me.

What I have tried:

Please help,

I want to export 6 million rows of access database into access.
I got a VBA code but it only exports 1 sheet (max 1048576 row).
I need to export to excel into multiple sheets is fine for me.
Posted
Updated 11-Jan-20 21:25pm
Comments
[no name] 12-Jan-20 2:22am    
Please check you question again. For me it looks you mixed up access and excel: "I want to export 6 million rows of access database into access"? Use Editing a Question[^] to edit your question
[no name] 12-Jan-20 2:27am    
If multiple excel sheets is ok, why you don't just do it?

1048576 is the maximum number of rows that a worksheet can contain. You need to adjust your code to start a new worksheet or workbook when you reach this limit.
 
Share this answer
 
Comments
Maciej Los 12-Jan-20 7:36am    
True!
One way to do this could be to run multiple queries which each produce a partial set of the data from the table. After executing the query you can export it to Excel.

In order to do this, you should design your query so that each executions return maximum of 1048576 rows. How to do this depends on the data in your table.

In general the idea could be something like
VB
FirstKeyValue = 0
LimitKeyValue = 1048576
NameCounter = 1

while FirstKeyValue <= MaxKeyValueInTable
   DoCmd.OpenQuery "QueryWhichFetchesTheKeyRange", acViewNormal, acEdit
   DoCmd.OutputTo acOutputQuery, , acFormatXLS, "FilePathAndName" & NameCounter & ".xls", True

   LimitKeyValue = LimitKeyValue + 1048576
   FirstKeyValue = FirstKeyValue + 1048576
   NameCounter = NameCounter + 1
wend

After the spreadsheets are created, you can continue to merge the files either on Access or Excel side. Probably could be easier to do this on Excel side using a single master file which contains a macro which would collect all the partial sheets to a single file.

References:
- DoCmd.OpenQuery method (Access) | Microsoft Docs[^]
- DoCmd.OutputTo method (Access) | Microsoft Docs[^]
 
Share this answer
 
Comments
Maciej Los 12-Jan-20 7:36am    
Great answer!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900