【发布时间】:2020-07-13 20:38:07
【问题描述】:
我有两个函数可以根据相同的标准打开和保存两个不同的报告。除了引用之外,它们是相同的:
Function Export_MLR()
On Error GoTo Export_MLR_Err
Dim strReportName As String
DoCmd.OpenReport "Market Rate Notification Final", acViewPreview
strReportName = "S:\National Installations\Market Labor Rates\MLR_INV\MLR\" & Format (Reports![Market Rate Notification Final].Market_ID, "00") & " " & Replace(Reports![Market Rate Notification Final].Product_Code, " / ", "_") & "-" & "Market Rate Notification Final" & "_" & Format(Date, "mmddyy") & ".pdf"
DoCmd.OutputTo acOutputReport, "Market Rate Notification Final", "PDFFormat(*.pdf)", strReportName, False, , , acExportQualityScreen
DoCmd.Close acReport, "Market Rate Notification Final", acSaveNo
Export_MLR_Exit:
Exit Function
Export_MLR_Err:
MsgBox Error$
Resume Export_MLR_Exit
End Function
然后我创建了这个函数来选择数据并将其逐行放入报告引用的表格中:
Function MassMarket()
On Error GoTo MassMarket_ERR
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
'this query creates my rs1 recordset'
DoCmd.SetWarnings (warningsOff)
DoCmd.OpenQuery "mass_market", acNormal, acEdit
DoCmd.SetWarnings (warningsOn)
Set db = CurrentDb()
Set rs1 = db.OpenRecordset("Mass_market_Rate_change")
Set rs2 = db.OpenRecordset("tbl_Form_Auto")
'this checks and clears any records in rs2'
If rs2.EOF = False And rs2.BOF = False Then
rs2.MoveFirst
rs2.Delete
End If
rs1.MoveFirst
'loop goes through and adds 1 line runs reports saves them and deletes line'
Do Until rs1.EOF
Set rs2 = db.OpenRecordset("tbl_Form_Auto")
rs2.AddNew
rs2![MarketID] = rs1![MarketID]
rs2![Product_ID] = rs1![Product_ID]
rs2.Update
Call Export_Invoice
Call Export_MLR
rs1.MoveNext
rs2.MoveFirst
rs2.Delete
Loop
MassMarket_Exit:
Exit Function
MassMarket_ERR:
MsgBox Error$
Resume MassMarket_Exit
End Function
现在所有这一切都像一个魅力,但它平均每分钟创建 16 个 .pdf 文件,而我必须创建 820 个 .pdf 文件(大约 50 分钟)。如果这是我能做的最好的,那么我会接受它,但如果可能的话,我很想把这个时间减半。感谢您的任何和所有输入。天然橡胶
【问题讨论】:
-
为了清楚起见,Export_Invoice 和 Export_MLR 最终使用来自 tbl_Form_Auto 的数据?
-
Export_Invoice 和 Export_MLR 打开报告,使用 tbl_Form_Auto 运行查询来填充报告。谢谢!
-
在你的 Do Until rs1.EOF 循环中,是否需要在每次循环时查询“tbl_Form_Auto,或者你可以在进入循环之前打开记录集吗?每次循环重复时都可以查询表向循环中添加大量且不必要的查询执行时间。
-
@texastubbs tbl_form_auto 是报告显示数据的暂存区。我为市场上的每种产品创建一个 pdf。每个市场都有多种产品。所以第一次将是市场 = 1 个产品 =1 第二次可能是市场 = 74 个产品 = 5。我希望只有一份庞大的报告,但每个报告必须将它们分解为 1 个市场 1 个产品。
-
@HasnsUp 我经历了多次,对我来说,这两个函数似乎占用了最多的时间。每个函数都会打开其受尊重的报表并运行查询以填充表单,然后保存并关闭。如果我今天有时间,我想我会仔细研究报告背后的查询,看看我是否可以在那里改变一些东西。同时感谢您的帮助。
标签: ms-access vba ms-access-2010