Share via

MS Access Export Report to PDF

Anonymous
2021-03-07T12:43:06+00:00

Hi:)I have a question.I am starting to develop a database in MS Access. I'm almost done.My question is the following.

Is it possible that a new report is automatically generated in PDF when a new entry is added for the current month

I will try show what I mean by help of pictures.

I have this menu

Here I have to invoice

When I press "Generer Faktura" = Generate Invoice

Comes all the invoices in the same generation.

What I would like the code to do is if I highlight the date 01-04-2021 and press the button generate invoice it is only for this month of invoice which is included

I have this code I am working on

On Error GoTo Err_Handler

    Const FOLDER_EXISTS = 75

    Const MESSAGE_TEXT_1 = "No folder set for storing PDF files."

    Const MESSAGE_TEXT_2 = "No invoice(s) selected."

    Dim strFullPath As String

    Dim varFolder As Variant

    Dim varFolder_1 As Variant

    Dim varItem As Variant

    ' build path to save PDF file

    varFolder = DLookup("Folderpath", "pdfFolder")

    If IsNull(varFolder) Then

        MsgBox MESSAGE_TEXT_1, vbExclamation, "Invalid Operation"

    Else

        With Me.lstInvoices

            If .ItemsSelected.Count > 0 Then

                For Each varItem In .ItemsSelected

                    Me.txtFaktura = .ItemData(varItem)

                    ' create folder if does not exist

                    varFolder_1 = varFolder & "" & .Column(1, varItem)

                    MkDir varFolder_1

                    strFullPath = varFolder_1 & "" & .Column(1, varItem) & " " & .ItemData(varItem) & ".pdf"

                    DoCmd.OutputTo acOutputReport, "Faktura", acFormatPDF, strFullPath, True

                Next varItem

            Else

                MsgBox MESSAGE_TEXT_2, vbExclamation, "Invalid Operation"

            End If

        End With

    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

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2021-03-07T19:33:28+00:00

    I thank you many time for your answer.

    It's nice of you. Would you mind, whos I send the file to you. I'm reasonably new to Access and VBA.

    Thank you in advance for your help.

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2021-03-07T18:06:58+00:00

    DoCmd.OutputTo will run the report and export it.

    The trick here is to have the report's underlying query "look back" at the form to pick up the date and use it to restrict the records.

    Something like:

    select * from Invoices

    where InvoiceDate = Forms!myForm!myDateField

    Was this answer helpful?

    0 comments No comments