Generate multiple files from the access based on the count of records (1 Viewer)

Jovial

Registered User.
Local time
Today, 01:37
Joined
Jan 21, 2015
Messages
29
My criteria is to generate the multiple excel files if the records on the table exceeds more than 400. Basic steps are:
1. Check the counts of records in the table
2. Open the template and delete the existing data
3. if counts > 400, grab above template and populate with 400 records and save as template 1
4. If there are more records in the table (lets say table has 1200 rows), then it will generate the 3 files and save as template 1, 2 and 3
how can this be achieved?
 

Ranman256

Well-known member
Local time
Today, 04:37
Joined
Apr 9, 2015
Messages
4,337
save as 3 separate XL files, or 3 tabs in a single XL file?
 

Ranman256

Well-known member
Local time
Today, 04:37
Joined
Apr 9, 2015
Messages
4,337
Code:
'export data to excel in various tabs using a max record count
'the table has a field [MARK] that is used to mark the records that have been sent. true= sent

'qsTopUmMarked = select query with top 400 where [MARK]=false
'quMarkTopRecs = update query to mark top 400 where [MARK]=false to TRUE  ,so they dont show anymore.

sub ExportXL2Sheets()
dim i as integer
dim sFile as string, sTab as string
dim lCount as long
const kMAXrecs = 400

docmd.setwarnings false

sFile = "c:\folder\DataExport" & format(date(),"yymmdd-hhnn") & ".xls"
lCount = Dcount("*","qsTopUnMarked")

i = 0
while lCount > 0
     i = i + 1
     sTab = "tab-" & i
     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qsTopUnMarked", sFile, True, sTab
     docmd.openquery "quMarkTopRecs"   'mark those sent

     lCount = Dcount("*","qsTopUnMarked")
wend 
docmd.setwarnings true
end sub
 

Jovial

Registered User.
Local time
Today, 01:37
Joined
Jan 21, 2015
Messages
29
I want to create the separate files and saved it as template 1, template 2 and template 3
 

Users who are viewing this thread

Top Bottom