Public Sub ReportGenerator(strAccount As String, strReportDate As String, strReportHeader As String)
Dim wbk As Excel.Workbook, wks As Excel.Worksheet
Dim rngStartRange As Excel.Range
Dim strIssues As String, rngIssues As Range, qdfIssues As QueryDef
Dim objExcel As Excel.Application
Set db = CurrentDb
strIssues = "SELECT Account, TopicHeader, Value1, Value2 " & _
"FROM tblReportDataSource " & _
"WHERE Account = '" & strAccount & "' AND TopicHeader IN('# Issues','Market Value ($B)') "
If DoesObjectExist("qryIssues", "Query") Then DoCmd.DeleteObject acQuery, "qryIssues"
Set qdfIssues = db.CreateQueryDef("qryIssues", strIssues)
Set rst = db.OpenRecordset("qryIssues", acQuery)
Set objExcel = New Excel.Application
objExcel.Visible = True
Set wbk = objExcel.Workbooks.Open("N:\US\US Client Relationship & Business Development\Client Reporting\Private\New Client Reporting\Client Service\Sandra\PROJECTS\JerrysProject\ReportTemplate.xls")
Set wks = wbk.ActiveSheet
With wks
.Range("FundNumber").value = "Fund Number " & strAccount
.Range("ReportDate").value = "Period Ending " & strReportDate
.Range("ReportHeader").value = strReportHeader
End With
Set rngIssues = wks.Range("Issues")
wks.Range("Issues").CopyFromRecordset rst
rst.Close
|