none
Report export pdf split RRS feed

  • Question

  • Hi,

    I currently have a report I am running that I want split in to multiple files in their own folders (which I can get currently) although, with the script I am using I have to click a button located next to the student ID I want the report for - which is going to take for ever to get through 800+ students.
    Is there a way I can modify the script I have to click 1 button to get every students report printed to file, still being separated and in their own folder?

    Thanks,

    Paul

    Option Compare Database
    
    Private Sub Command46_Click()
    On Error GoTo Err_Handler
        
        Const FOLDER_EXISTS = 75
        Const MESSAGE_TEXT1 = "No current details."
        Const MESSAGE_TEXT2 = "No folder set for storing PDF files."
        Dim strFullPath As String
        Dim varFolder As Variant
        Dim strDate As String
        
        strDate = Format(Now(), "ddmmyyyy")
               
        If Not IsNull(Me.Student_ID) Then
            ' build path to save PDF file
            varFolder = DLookup("Folderpath", "pdfFolder")
            If IsNull(varFolder) Then
                MsgBox MESSAGE_TEXT2, vbExclamation, "Invalid Operation"
            Else
                ' create folder if does not exist
                varFolder = varFolder & "\" & Me.Student_ID
                MkDir varFolder
                strFullPath = varFolder & "\" & Me.Student_ID & " " & strDate & ".pdf"
                ' ensure current record is saved before creating PDF file
                Me.Dirty = False
                DoCmd.OpenReport "StHistory", acViewPreview, , "[Student.Student_ID] = '" & Me![Student_ID] & "'"
                DoCmd.OutputTo acOutputReport, "StHistory", acFormatPDF, strFullPath, True
                DoCmd.Close acReport, "StHistory"
            End If
        Else
            MsgBox MESSAGE_TEXT1, vbExclamation, "Invalid Operation"
        End If
     
    Exit_Here:
        Exit Sub
        
    Err_Handler:
        Select Case Err.Number
            Case FOLDER_EXISTS
            Resume Next
            Case Else
            MsgBox Err.Description
            Resume Exit_Here
        End Select
     
    End Sub
    


    Sunday, January 17, 2016 12:08 PM

Answers

  • >>>Is there a way I can modify the script I have to click 1 button to get every students report printed to file, still being separated and in their own folder?

    According to your description, if I don't misunderstand, you could loop through a form by moving to the next record in the recordset, refer to below code:

    While Me.CurrentRecord < Me.Recordset.RecordCount
        ' ... do something to current record
        ' ...
    
        DoCmd.GoToRecord Record:=acNext
    Wend
    

    For more information, click here to refer about DoCmd.GoToRecord Method (Access)

    • Marked as answer by David_JunFeng Tuesday, January 26, 2016 2:13 AM
    Monday, January 18, 2016 2:33 AM