出口到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