Results 1 to 8 of 8
  1. #1
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21

    Export Query to Specific Sheet and Rows/Columns



    Code:
    Private Sub Command3_Click()
     
        Dim reportName As String
        Dim theFilePath As String
     
    ''    On Error Resume Next
        Select Case Me.Frame4.Value
            Case 1
                reportName = "Query1"
            Case 2
                reportName = "Query2"
        End Select
     
        theFilePath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\"
        theFilePath = theFilePath & reportName & ".xlsx"
     
        DoCmd.TransferSpreadsheet acExport, 10, reportName, theFilePath, True
        MsgBox "Check your Desktop."
     
    End Sub
    Running the above code on a button. Is it possible to add options to the export to tell it a particular sheet and/or particular rows and columns.

    Thanks,

  2. #2
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    Read this link about saving to a particular range in a particular spreadsheet. This was written for an earlier version of Access so be sure not to change the Transfer spreadsheet section of the docmd line but only the end of the code line.
    http://accessblog.net/2006/07/export...cel-range.html
    Alan

  3. #3
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Quote Originally Posted by alansidman View Post
    Read this link about saving to a particular range in a particular spreadsheet. This was written for an earlier version of Access so be sure not to change the Transfer spreadsheet section of the docmd line but only the end of the code line.
    http://accessblog.net/2006/07/export...cel-range.html
    Alan
    Thank you Alan,

    I had beed playing with the [Range] portion of the command but specifically could not get the Sheet+range to work. Perhaps it is how I am writing it. To go off of your blog link if I am creating an export to the "myname" sheet, how can I further direct it to exporting to a specific range of cells. Simply myname$A3:BA3 would not work. I saw in a response below that

    "Was just able to export to Excel from Access 2007 to specific range using:
    Call Application.DoCmd.TransferSpreadsheet(acExport, acSpreadsheetTypeExcel8, Access_Table, FullPathToExcelWorkbook.xls, False, Sheet1$A3:BA3)"

    I am not having the same luck

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    What does your docmd line look like when you try to export to a specific range and spreadsheet.

  5. #5
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Code:
        DoCmd.TransferSpreadsheet acExport, 10, reportName, theFilePath, True, myname$A2:B5

  6. #6
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Any Ideas?

  7. #7
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    I can't get it to work either. I'm hoping someone who has used this concept will jump in here.

  8. #8
    chewbears is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    21
    Thanks for the reply Alan. Been trying all sorts of things, but always getting the same error ; P

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

Similar Threads

  1. Table rows to columns
    By Rhino373 in forum Programming
    Replies: 5
    Last Post: 12-22-2011, 01:44 PM
  2. Showing Columns & Rows in Crosstab query
    By coach32 in forum Queries
    Replies: 6
    Last Post: 09-11-2011, 07:01 PM
  3. Replies: 1
    Last Post: 04-17-2011, 04:16 PM
  4. Replies: 1
    Last Post: 01-24-2011, 03:03 PM
  5. Replies: 2
    Last Post: 07-15-2009, 04:08 AM

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