OsvaldoLaviosa ha scritto:
Mostra il nuovo codice che, senza l'uso di tutti quei Filter, FilterOn… assume tutto un altro significato.
Dim rs                    As DAO.Recordset
    Dim rpt                   As Access.Report
    Dim sFolder               As String
    Dim sFile                 As String
    Const sReportName = "Report1"
    On Error GoTo Error_Handler
    sFolder = "C:\Users\Mafra8\Desktop\Master\"
    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(![Titolo_FILE], "") & " " & Nz(![Titolo], "") & " " & ".pdf"
                sFile = sFolder & sFile
            
                rpt.Filter = "[ID]=" & ![ID]
                rpt.FilterOn = True
                DoEvents
                DoCmd.OutputTo acOutputReport, sReportName, acFormatPDF, sFile, , , , acExportQualityPrint
               Call Sleep(1000)
                .MoveNext
            Loop
            DoCmd.Close acReport, sReportName
        End If
    End With
Error_Handler_Exit:
    On Error Resume Next
    If Not rpt Is Nothing Then Set rpt = Nothing
    If Not rs Is Nothing Then
        rs.Close
        Set rs = Nothing
    End If
    Exit Sub
Error_Handler:
    If Err.Number <> 2501 Then
        MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Numero & vbCrLf & _
               "Error Source: cmd_Click" & vbCrLf & _
               "Error Description: " & Err.Description & _
               Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
               , vbOKOnly + vbCritical, "An Error has Occured!"
    End If
    Resume Error_Handler_Exit
End Sub