Here is something that I created that could work, if you don't mind making
temptables.
I create a temptable with all of our buyers and then in the export use a
similar recordset and loop to export and it works like a charm. You could
also add a delete
temp table to the loop after the export in order to save space. My export
is under a different sub, but if you were constantly exporting to the same
filepath or wanted to add an input box for the file path you could include it
all under one sub.
This is one of my first offers to assist, so if you don't mind, please
respond back if it was helpful or I should keep my ideas to myself.
Thanks!
Roger
Private Sub btnCreateICRIF_Files_Click()
Dim strSql As String, Booisit As Boolean, dbs As Database, rst As Recordset,
strBuyer As String
'Turn Warnings off
DoCmd.SetWarnings False
DoCmd.Hourglass (True)
Me.txtInvFillPlsWait.Visible = True
DoCmd.RepaintObject
'Remove old tables ICRIFPt1 & ICRIFPt2
Call Subs.TableisThere(Booisit, "ICRIFPt1")
If Booisit = True Then DoCmd.DeleteObject acTable, "ICRIFPt1"
Call Subs.TableisThere(Booisit, "ICRIFPt2")
If Booisit = True Then DoCmd.DeleteObject acTable, "ICRIFPt2"
'Create the ICRIF Part 1 table
strSql = "SELECT tblICRIF.Whse, tblICRIF.Product, tblICRIF.Description,
tblICRIF.Buyer, tblICRIF.[Vendor #], tblICRIF.[Vendor Name]," _
& " tblICRIF.[Replenishment Source], tblICRIF.Class, tblICRIF.[$ Ordered],
tblICRIF.[$ Shipped], tblICRIF.[$ Fill Pct]," _
& " tblICRIF.[Qty Ordered], tblICRIF.[Qty Shipped], tblICRIF.[Fill Pct],
tblICRIF.[# Lines], tblICRIF.[# Complete Lines]," _
& " tblICRIF.[Line Fill Pct] INTO ICRIFPt1 FROM tblICRIF WHERE
(((tblICRIF.Whse)<='TAMP')) ORDER BY tblICRIF.Whse;"
DoCmd.RunSQL (strSql)
Set dbs = CurrentDb()
strSql = "SELECT ICRIFPt1.Buyer FROM ICRIFPt1 GROUP BY ICRIFPt1.Buyer;"
Set rst = dbs.OpenRecordset(strSql)
Do Until rst.EOF = True
strBuyer = rst!Buyer
'Create the temp tables for export by buyer sorted in descending Fill
percent
strSql = "SELECT ICRIFPt1.Whse, ICRIFPt1.Product, ICRIFPt1.Description,
ICRIFPt1.Buyer, ICRIFPt1.[Vendor #]," _
& " ICRIFPt1.[Vendor Name], ICRIFPt1.[Replenishment Source],
ICRIFPt1.Class, ICRIFPt1.[$ Ordered], ICRIFPt1.[$ Shipped]," _
& " ICRIFPt1.[$ Fill Pct], ICRIFPt1.[Qty Ordered], ICRIFPt1.[Qty
Shipped], ICRIFPt1.[Fill Pct], ICRIFPt1.[# Lines]," _
& " ICRIFPt1.[# Complete Lines], ICRIFPt1.[Line Fill Pct] INTO temp" &
strBuyer & " FROM ICRIFPt1" _
& " WHERE (((ICRIFPt1.Buyer) = '" & strBuyer & "')) ORDER BY
ICRIFPt1.[Line Fill Pct];"
DoCmd.RunSQL (strSql)
rst.MoveNext
Loop
Me.txtInvFillPlsWait.Visible = False
'Turn Warnings on
DoCmd.SetWarnings True
DoCmd.Hourglass (False)
MsgBox "The ICRIF table has been created and is ready to export.", vbOKOnly,
msglbl
End Sub
andrewbecks said:
Hello. I am looking for some help in exporting a query to Excel.
Currently, I have a query that has four columns:
-District_Manager
-Store_Number
-Fiscal_Week
-Sales_Dollars
There are approx. 200 different District Managers, and each District
Manager has about 10 lines of data. What I would love to do is have a
seperate excel file generated for each District Manager, that includes
only his or her information. I'd like the Excel files to have the name
of the District Manager.
So, for District Manager Joe Example, an excel file named [Joe
Example.xls] would be created that includes the above query but only
includes row where the value for District Manager is Joe Example.
Any assistance with this would be GREATLY appreciate.
Andrew