Loops 访问报告,按组打印pdf
我对VBA还是相当陌生的。我一直在绞尽脑汁,查看每个论坛,试图找到如何做到这一点。这是我迄今为止最接近的一次。 我有一张名为Streets的表格,它是一份报告的基础,显示了每条街道的房屋数量。每个记录都在一个名为StreetPrintOuts的报告的一页上。我将街道划分为不同的区域,这些区域(MapNum)都已编号。我希望每个pdf都能显示其所在地区每条街道的所有街道记录。到目前为止,我有:Loops 访问报告,按组打印pdf,loops,ms-access,vba,pdf-generation,ms-access-2007,Loops,Ms Access,Vba,Pdf Generation,Ms Access 2007,我对VBA还是相当陌生的。我一直在绞尽脑汁,查看每个论坛,试图找到如何做到这一点。这是我迄今为止最接近的一次。 我有一张名为Streets的表格,它是一份报告的基础,显示了每条街道的房屋数量。每个记录都在一个名为StreetPrintOuts的报告的一页上。我将街道划分为不同的区域,这些区域(MapNum)都已编号。我希望每个pdf都能显示其所在地区每条街道的所有街道记录。到目前为止,我有: Public Sub PDFGroup_Click() Const Folder = "C:\Users
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错误:输出操作已取消
我做错了什么?这段代码确实有效。我留下了另一个变量,使其在报告的其他地方中断。显然,工作到深夜,错过了一些东西