0
我對VBA還是比較新的。我一直在絞盡腦汁,看着每一個試圖找到如何做到這一點的論壇。這是迄今爲止我所得到的最接近的。 我有一張名爲「街道」的表格,報告基於此,顯示了每條街道的房屋數量。每條記錄位於名爲StreetPrintOuts的報告的單個頁面上。我把街道分成不同的地區,而這些地區(MapNum)都有編號。我希望每個pdf都能顯示該地區每條街道的所有街道記錄。到目前爲止,我有這樣的:訪問報告,每組打印pdf
Public Sub PDFGroup_Click()
Const Folder = "C:\Users\Records\"
Const Domain = "Streets"
'Domain can be table name, query name, or sql statement that provides the values to loop
Const LoopedField = "MapNum"
Const ReportName = "StreetPrintOuts"
Dim rs As DAO.Recordset
Dim LoopedFieldValue As Long
Dim FileName As String
Dim FullPath As String
Dim strWhere As String
Set rs = CurrentDb.OpenRecordset(Domain)
Do While Not rs.EOF
LoopedFieldValue = rs.Fields(LoopedField)
FileName = LoopedFieldValue & ".pdf"
'The field may be a text field. It then must be surrounded in singlequotes. If so uncomment below
'LoopedFieldValue = "'" & LoopedFieldValue & "'"
FullPath = Folder & FileName
strWhere = LoopedField & " = " & LoopedFieldValue
Debug.Print FullPath
Debug.Print strWhere
DoCmd.OpenReport ReportName, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, FullPath
DoCmd.Close acReport, ReportName
rs.MoveNext
Loop
End Sub
它運行時,它都會經過
DoCmd.OpenReport ReportName, acViewPreview, , strWhere
停止,錯誤代碼運行時錯誤2501:OutputTo操作被取消
我在做什麼錯?