出口到PDF优化VBA代码,我有两个功能,将打开和保存基于同一标准的2个指出错误报告。他们是相同的除了refrences:是从MS Access
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
然后,我创建了这个功能来选择数据,并把它放到桌上,这些报告refrence逐行:
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分钟)。如果这是我能做的最好的,那么我会接受它,但如果可能的话,希望将这个时间减半。感谢任何和所有的输入。 NR
只是为了清楚起见,Export_Invoice和Export_MLR最终使用从tbl_Form_Auto的数据? –
Export_Invoice和Export_MLR使用tbl_Form_Auto打开报告以运行报告,以填充报告。谢谢! –
在做,直到rs1.EOF循环,是necesary每次循环时间查询“tbl_Form_Auto,或者你可以进入循环前打开记录?每次循环重复都不可能添加显著和unneceesary查询执行时间查询表to the loop。 – EastOfJupiter