E
ecapox via AccessMonster.com
My issue is this....
I have the current code below that works great and does everything i want it
to do...with one exception. When it exports these queries to Excel
spreadsheets, i would like it to use an Excel template i have set up. I would
like that because the Excel template contains some code that the users of the
spreadsheets will need to use, and it contains a few formatting issues they
need. Also, since i will be using a template, i need to tell my code to isert
the query results beginning on line 4 of each spreadsheet...not line 1 as it
currently does.
Your help is greatly appreciated.
Now for the code....
Public Sub Export()
'Start of code
Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset
Dim strSQL As String
' Define the query that will be used for exporting
Const strQName As String = "qselExportCompare"
Set dbs = CurrentDb()
' Create tax entity recordset that will be looped through
strSQL = "SELECT DISTINCT sTaxCode FROM dbo_TIFTRFd_Entity;"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
' Loop through list of entities and export data to excel file by entity
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst
Do While rst.EOF = False
strSQL = "TRANSFORM Sum(qSelExportFormat.nPYAmount) AS SumOfnPYAmount
" _
& "SELECT qSelExportFormat.sTaxCode, qSelExportFormat.sStateID,
Sum(qSelExportFormat.nPYAmount) AS [Total Of nPYAmount] " _
& "FROM qSelExportFormat " _
& "WHERE sTaxCode = '" & rst!sTaxCode.Value & "' " _
& "GROUP BY qSelExportFormat.sTaxCode, qSelExportFormat.sStateID "
_
& "PIVOT qSelExportFormat.[Full Account]; "
Set qdf = CurrentDb.QueryDefs(strQName)
qdf.Name = strQName
qdf.sql = strSQL
qdf.Close
Set qdf = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExce9, _
strQName, "O:\TECHNOLOGY\TaxWeb\IFTRF\Export\" & rst!sTaxCode.
Value & ".xls"
rst.MoveNext
Loop
End If
rstMgr.Close
Set rstMgr = Nothing
dbs.Close
Set dbs = Nothing
'End of code
End Sub
I have the current code below that works great and does everything i want it
to do...with one exception. When it exports these queries to Excel
spreadsheets, i would like it to use an Excel template i have set up. I would
like that because the Excel template contains some code that the users of the
spreadsheets will need to use, and it contains a few formatting issues they
need. Also, since i will be using a template, i need to tell my code to isert
the query results beginning on line 4 of each spreadsheet...not line 1 as it
currently does.
Your help is greatly appreciated.
Now for the code....
Public Sub Export()
'Start of code
Dim qdf As DAO.QueryDef
Dim dbs As DAO.Database
Dim rstMgr As DAO.Recordset
Dim strSQL As String
' Define the query that will be used for exporting
Const strQName As String = "qselExportCompare"
Set dbs = CurrentDb()
' Create tax entity recordset that will be looped through
strSQL = "SELECT DISTINCT sTaxCode FROM dbo_TIFTRFd_Entity;"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset, dbReadOnly)
' Loop through list of entities and export data to excel file by entity
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst
Do While rst.EOF = False
strSQL = "TRANSFORM Sum(qSelExportFormat.nPYAmount) AS SumOfnPYAmount
" _
& "SELECT qSelExportFormat.sTaxCode, qSelExportFormat.sStateID,
Sum(qSelExportFormat.nPYAmount) AS [Total Of nPYAmount] " _
& "FROM qSelExportFormat " _
& "WHERE sTaxCode = '" & rst!sTaxCode.Value & "' " _
& "GROUP BY qSelExportFormat.sTaxCode, qSelExportFormat.sStateID "
_
& "PIVOT qSelExportFormat.[Full Account]; "
Set qdf = CurrentDb.QueryDefs(strQName)
qdf.Name = strQName
qdf.sql = strSQL
qdf.Close
Set qdf = Nothing
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExce9, _
strQName, "O:\TECHNOLOGY\TaxWeb\IFTRF\Export\" & rst!sTaxCode.
Value & ".xls"
rst.MoveNext
Loop
End If
rstMgr.Close
Set rstMgr = Nothing
dbs.Close
Set dbs = Nothing
'End of code
End Sub