目前,我已经改编了从Allen Brown获得的代码来复制报告而不是表单。基本上我能够毫无问题地通过我的报告标准,我可以用不同的标准创建一些报告。
我的问题是每个报告可能需要保存,打印或通过电子邮件发送给用户。但是会发生的事情是首先打开的对象是唯一可以保存或通过电子邮件发送的对象,但是当我使用简单代码DoCmd.PrintOut acPrintAll
进行打印时,每个对象都会采用相应的标准。我需要找到一种方法来保存和发送这些对象。
报告可通过设置为它的HWND属性进行区分。我现在的代码就是这个:
Public clnClient As New Collection 'Instances of rptClient.
'Purpose: Open an independent instance of each Report with seperate criteria
Dim rpt As Report
'Open a new instance, show it, and set a caption.
If strReport = "rptInvoices" Then
Set rpt = New Report_rptInvoices
ElseIf strReport = "rptExpense" Then
Set rpt = New Report_rptExpense
ElseIf strReport = "rptExpensesDetailed" Then
Set rpt = New Report_rptExpenseDetailed
ElseIf strReport = "rptInvoicesDetailed" Then
Set rpt = New Report_rptInvoicesDetailed
ElseIf strReport = "rptPuchaseOrder" Then
Set rpt = New Report_rptPuchaseOrder
ElseIf strReport = "rptPurchaseOrderDetail" Then
Set rpt = New Report_rptPurchaseOrderDetail
ElseIf strReport = "TotalSalesForYear" Then
Set rpt = New Report_TotalSalesForYear
ElseIf strReport = "TotalShipped" Then
Set rpt = New Report_TotalShipped
ElseIf strReport = "TotalShippedDetailed" Then
Set rpt = New Report_TotalShippedDetailed
ElseIf strReport = "rptShipActual" Then
Set rpt = New Report_rptShipActual
ElseIf strReport = "rptSearchResults" Then
Set rpt = New Report_rptSearchResults
ElseIf strReport = "rptKTNA" Then
Set rpt = New Report_rptKTNA
ElseIf strReport = "rptFourWeek" Then
Set rpt = New Report_rptFourWeek
ElseIf strReport = "rptBalance" Then
Set rpt = New Report_rptBalance
ElseIf strReport = "Bosch_Report" Then
Set rpt = New Report_Bosch_Report
ElseIf strReport = "rptQuotes" Then
Set rpt = New Report_rptQuotes
End If
rpt.Visible = True
rpt.Filter = strWhereDate
rpt.FilterOn = True
rpt.Caption = rpt.Hwnd & ", opened " & Now()
rpt.txtCalledFrom = rpt.Hwnd
'Append it to our collection.
clnClient.Add Item:=rpt, Key:=CStr(rpt.Hwnd)
Set rpt = Nothing
strReport是报告的名称,strWhereDate是用于时间间隔的内容。此处未列出的代码会在报告关闭时从集合中删除rpt.hwnd。
通过标准的报告管理员改编自Gaining Access
我想知道字典是否比集合更好用,但我已经尝试调整代码而我似乎无法使其正常工作,我知道字典是可以引用对象。我也试过这段代码:
sRep = Screen.ActiveReport.Hwnd
DoCmd.OutputTo acOutputReport, sRep, acFormatPDF
可以准确找到hwnd,它甚至会打开对话框,使用名称hwnd.pdf将其保存到某个位置,但我担心保存后它不会出现。我假设对象在技术上不存在?
如果你试图解决这个问题,请知道我是新手。请帮忙!!!