Results 1 to 8 of 8
  1. #1
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76

    export to excel starting from Cell A2

    Hi dear all, I asked the export to excel question and get lots of help here, Thank you all so much!
    Now my code is working prefectly with the ability that can export multiple queries to multiple worksheets. I just have one question here: Is there a way that I can make my data transfered starting from cell A2? I tried the way: arrStr![A2:Z1000], but it gave me the error said: Qualifier must be collection...I would appreciate any help on this subject, Thanks a lot!!!


    Here is my original code:
    Code:
    Private Sub ExprDetail_Click()
    Dim db As DAO.Database
    Dim qdf1 As DAO.QueryDef
    Dim qdf2 As DAO.QueryDef
    Dim rst As Recordset
    Dim recordCnt As Integer
    Dim recordNm As Integer
    Dim sql As String
    Dim sqlFull As String
    Dim arrStr As String
    Dim arrCount() As String
    Dim path As String
    Dim strPrmp As String
    Dim strttl As String
    Dim DflPath As String
    DflPath = "C:\Documents and Settings\WangA\My Documents\Export_Excel_Files\FNexcel.xls"
    strPrmp = "Would you like to name your Excel File?"
    strttl = "Excel export"
    path = InputBox(strPrmp, strttl, DflPath)
    Const JOIN_SEP = ""","""
    
    Set db = CurrentDb()
    Set qdf1 = db.QueryDefs("RecordExcel")
    Set rst = qdf1.OpenRecordset
    recordCnt = rst.RecordCount
    ReDim arrCount(1 To recordCnt) As String
    rst.MoveFirst
    For recordNm = 1 To recordCnt
        Set qdf2 = db.QueryDefs("DivideGroup")
        
        arrCount(recordNm) = rst!grouping
        arrStr = """" & arrCount(recordNm) & """"
            sql = "TRANSFORM Sum(Format_Step3.SumOfCatch) AS SumOfSumOfCatch SELECT Format_Step3.TimeGroup AS [Year] " _
                 & "FROM Format_Step3 INNER JOIN RecordExcel ON Format_Step3.grouping = RecordExcel.grouping WHERE (((RecordExcel.grouping) In (" & arrStr & "))) " _
                 & "GROUP BY Format_Step3.TimeGroup, RecordExcel.grouping ORDER BY Format_Step3.TimeGroup PIVOT Format_Step3.ClnVar;"
            qdf2.sql = sql
            DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "DivideGroup", path, True, arrStr
       
        rst.MoveNext
        qdf2.Close
        
        Set qdf2 = Nothing
       
    Next recordNm
        
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What does arrStr hold?

    Need to reference sheet name, like:

    "Sheet1!A2:Z1000"

    If arrStr is a variable holding sheet name then concatenate:

    arrStr & "!A2:Z1000"
    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
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Thanks so much, I have tried both way but none of them worked. I guess it because arrStr is an array string in my code...Is any way that I can apply the array variable in this situation?

    Quote Originally Posted by June7 View Post
    If arrStr is a variable holding sheet name then concatenate:

    arrStr & "!A2:Z1000"

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Wait, because you wanted to specify a range I 'read' export as import.

    Transferspreadsheet cannot be used if you want to specify a start cell for export. Review http://msdn.microsoft.com/en-us/libr...ffice.12).aspx
    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
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Ok, I see... So if I need to specify the range I will need to change the code? Do you know which way I can change it? Can you provide me an example? Thanks a lot!!!
    Quote Originally Posted by June7 View Post
    Wait, because you wanted to specify a range I 'read' export as import.

    Transferspreadsheet cannot be used if you want to specify a start cell for export. Review http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Review http://forums.aspfree.com/microsoft-...el-414974.html

    Look at the two additional links in the last post.
    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
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Dear, the website you provide is can not be found :P
    Quote Originally Posted by June7 View Post
    Review http://forums.aspfree.com/microsoft-...el-414974.html

    Look at the two additional links in the last post.

  8. #8
    ice051505 is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Feb 2013
    Posts
    76
    Sorry...the website is worked...my bad...

    Quote Originally Posted by June7 View Post
    Review http://forums.aspfree.com/microsoft-...el-414974.html

    Look at the two additional links in the last post.

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

Similar Threads

  1. Export Query to .ODS file starting at a specific cell
    By Baldeagle in forum Import/Export Data
    Replies: 4
    Last Post: 03-20-2013, 01:03 PM
  2. Data from Excel has Alt enter in a cell
    By newbee in forum Reports
    Replies: 1
    Last Post: 03-14-2013, 12:09 PM
  3. Replies: 4
    Last Post: 09-19-2012, 11:49 AM
  4. Export a value to specific Excel cell
    By gg80 in forum Import/Export Data
    Replies: 5
    Last Post: 07-23-2010, 01:58 PM
  5. Can we post Access cell data to Excel cell properties?
    By Zethro in forum Import/Export Data
    Replies: 1
    Last Post: 12-13-2005, 08:42 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