【问题标题】:(VBA) create a file "pdf" for each record in a table(VBA)为表中的每条记录创建一个文件“pdf”
【发布时间】:2020-09-21 01:09:18
【问题描述】:

帮帮我,我编写的这段代码创建了多个文件,但每个文件只包含第一条记录中的值: 我想要表格中每条记录的文件 pdf。

Option Compare Database 
Option Explicit

Private Declare PtrSafe Sub 
Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)

Private Sub Creazione_Click()
Dim rs As DAO.Recordset
Dim rpt As Access.Report
Dim sFolder As String
Dim sFile As String
Const sReportName = "Mandato"
sFolder = "C:\Users\Famiglia\Desktop\Mandati\"

Set rs = Me.RecordsetClone
With rs
If .RecordCount <> 0 Then
'Open the Report
DoCmd.OpenReport sReportName, acViewPreview, , , acHidden
'Define a report object so we can manipulate it below
Set rpt = Reports(sReportName).Report
.MoveFirst
Do While Not .EOF
'Build the PDF filename we are going to use to save the PDF with
sFile = Nz(![id], "") & " " & Nz(![COGNOME], "") & ".pdf"
sFile = sFolder & sFile
DoCmd.OutputTo acOutputReport, sReportName, acFormatPDF, sFile, , , , acExportQualityPrint
Call Sleep(1000)
DoEvents
.MoveNext
Loop
DoCmd.Close acReport, sReportName
End If
End With
End Sub    

【问题讨论】:

    标签: ms-access pdf printing report


    【解决方案1】:

    打开、输出、关闭过滤到循环内记录的报告。

    Do While Not .EOF
        DoCmd.OpenReport sReportName, acViewPreview, , "ID=" & rs!ID, acHidden
        ...
        DoCmd.Close acReport, sReportName
        .MoveNext
    Loop
    

    报表对象变量不是必需的。您的代码甚至没有使用该变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-08
      • 2019-10-17
      • 2016-11-19
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多