Results 1 to 14 of 14
  1. #1
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25

    Excel Export per unique field to separate workbooks

    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 workbooks 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 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

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    If you want to export to separate workbooks then need to change the name of the workbook for each export.

    You are not using the MyPath and MyFileName variables to construct the Excel file name.

    What is the temp variable for?

    Why does your posted code show & ?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25

    Excel Export per unique field to separate workbooks

    I basically copied the code from a working code which exports a report to pdf per unique field in this case brokerage so i thought would be a minor tweak to export to excel in the same way.

    I have never used the spreadsheet code before so am a little lost and so need it to sabe a few hours every week as i have to manually split 1 spreadsheet into 92 workbooks.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    So did you do the edits as suggested? Does code work now?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25

    Excel Export per unique field to separate workbooks

    Not working yet. Still battling with the code and searching the web. Maybe a little out my depth

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think all you need to do is:

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Commission Statement - 1Life Broker Services", MyPath & "\" & MyFileName
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25

    Excel Export per unique field to separate workbooks

    Thanks very much. Will try shortly. Richard

  8. #8
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25
    June7, you are an absolute star. Thanks very much and its working perfectly

    I am now going to fiddle around with formatting the excel output in terms of bold, auto centre and shading. I hope I can shout if I get stuck.

    Thanks again

    Rich

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    You want code in Access to perform those formatting actions in the Excel?

    That requires very different code that opens Excel and workbook objects in VBA. Gets rather complicated. Numerous threads have been devoted to the topic.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25
    All I want is for the exported excel file for the top row to be bold and shaded grey and the columns to be auto-centred. Is that a big ask?

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Doesn't matter how little or how much formatting you want, the method is the same.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25

    Excel Export per unique field to separate workbooks

    Thanks. Will check out options to see if i can do it. Thanks again.

  13. #13
    Fuzz_cozens is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    25
    [QUOTE=Fuzz_cozens;237414]June7, you are an absolute star. Thanks very much and its working perfectly

    June7, I just noticed that once I execute this code the excel is exported separately into the correct file name by"Brokerage" however in the workbooks is all of the data and not just the data of the respective "brokerage". Any ideas on this?

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Need to apply filter to the query. That can be complicated. It would be easier to open and export a filtered report.

    I just noticed the Recordset sql does not specify field(s) to retrieve. I am surprised it works.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 20
    Last Post: 03-13-2014, 12:50 PM
  2. Replies: 1
    Last Post: 03-11-2014, 09:29 AM
  3. Replies: 12
    Last Post: 12-17-2012, 12:47 PM
  4. Replies: 5
    Last Post: 07-06-2012, 03:22 PM
  5. Export Table in Access 2007 to Multiple Workbooks in Excel 2007
    By hutchinsm in forum Import/Export Data
    Replies: 5
    Last Post: 03-01-2012, 05:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums