HiI have a query which I would like to export to excel 2010 and would like separate files saved using a unique field called [Brokerage]. The code below exports the query however does not export separate worksheets as I am missing something perhaps the OutputTo function.Any help would be greatly appreciated
Private Sub Commission_Excel_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileName As String
Dim temp As String
Dim mypath As String
mypath = "C:\Users\Richard\Desktop\1Life Broker Services\Automatic Reports\Commission Excels\Commission Excel - "
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT distinct [Brokerage] FROM [Commission Statement - 1Life Broker Services]", dbOpenSnapshot)
Do While Not rs.EOF
temp = rs("brokerage")
MyFileName = rs("Brokerage") & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Commission Statement - 1Life Broker Services", "C:\Users\Richard\Desktop\1Life Broker Services\Automatic Reports\Commission Excels\Commission Excel - " & Format(Date, "dd/mm/yyyy") & ".xls", True
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub Commission_Excel_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileName As String
Dim temp As String
Dim mypath As String
mypath = "C:\Users\Richard\Desktop\1Life Broker Services\Automatic Reports\Commission Excels\Commission Excel - "
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT distinct [Brokerage] FROM [Commission Statement - 1Life Broker Services]", dbOpenSnapshot)
Do While Not rs.EOF
temp = rs("brokerage")
MyFileName = rs("Brokerage") & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Commission Statement - 1Life Broker Services", "C:\Users\Richard\Desktop\1Life Broker Services\Automatic Reports\Commission Excels\Commission Excel - " & Format(Date, "dd/mm/yyyy") & ".xls", True
DoEvents
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Last edited: