Create seperate PDF Files from a report Base on a query with more than 300 records (1 Viewer)

PJAY

New member
Local time
Yesterday, 23:44
Joined
Dec 30, 2023
Messages
4
I am trying to create PDF files (1 File per record). but i am stuck and it is not working below is my code.

Code:
Dim FileName As String
Dim FilePath As String

'FileName = Me.Hoten
'FilePath = "D:\" & FileName & ".pdf"
'DoCmd.OutputTo acOutputReport, "IIn", acFormatPDF, FilePath

    Dim rs As Object
    Dim iAns As Integer
    Dim sFolder As String
    
    
    iAns = MsgBox("Do you want to print ALL records?" & vbCrLf & vbCrLf & _
            "   Choose 'Yes' to print all records" & vbCrLf & _
            "   Chose 'No' to print the current record", vbQuestion + vbYesNoCancel)
    If iAns = vbYes Or iAns = vbNo Then
        sFolder = BrowseForFolder("Select a Folder to save the pdf")
        If Len(Trim$(sFolder)) = 0 Then
            sFolder = Environ("UserProfile") & "\Documents\"
            MsgBox "You have not selected any folder. The pdf(s) will be saved to Documents folder.", vbInformation
        End If
    End If
    If iAns = vbYes Then
        Set rs = Me.Recordset
        With rs
            If .RecordCount < 1 Then
                Exit Sub
            End If
            .MoveFirst
            Do Until .EOF
                FileName = UCase(Me.StudentFullName & "")
                FilePath = sFolder & FileName
                
                Call forceMKDir(FilePath)
                
                FilePath = FilePath & "\" & FileName & ".pdf"
                
                'FilePath = "D:\" & FileName & ".pdf"
                'FilePath = "C:\ARNEL\" & FileName & ".pdf"
                If Len(Dir$(FilePath)) <> 0 Then
                    Kill FilePath
                End If
                'DoCmd.SetParameter "p_HOTEN", FileName
                TempVars("p_Hoten") = FileName
                DoCmd.OutputTo acOutputReport, "IIn_all", acFormatPDF, FilePath
                .MoveNext
            Loop
        End With
        On Error Resume Next
        TempVars.Remove "p_Hoten"
        On Error GoTo 0
    ElseIf iAns = vbNo Then
        FileName = UCase(Me.StudentFullName & "")
        FilePath = sFolder & FileName
        
        Call forceMKDir(FilePath)
        
        FilePath = FilePath & "\" & FileName & ".pdf"
        'FilePath = "D:\" & FileName & ".pdf"
        'FilePath = "C:\ARNEL\" & FileName & ".pdf"
        If Len(Dir$(FilePath)) <> 0 Then
            Kill FilePath
        End If
        DoCmd.OutputTo acOutputReport, "Nest-Term1-Bill", acFormatPDF, FilePath
    End If


if i select NO it create all the PDF files in one single file
but if i Choose No it give me Error :

er3.jpg
 
upload your db, then it would be easy to modify, than bunch of snapshot screens.
just tell us which form you have trouble.
 
Again, you have to supply the line where the error occurs, just as was asked in the UA site. :(
 
I added a very simple piece of code to this post that should help you.

 

Users who are viewing this thread

Back
Top Bottom