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