Solved PDF Report output Issue - Access 2016 (1 Viewer)

RickHunter84

Registered User.
Local time
Today, 08:14
Joined
Dec 28, 2019
Messages
85
Hello there,

I'm trying to print a report into a PDF file to later attached it to an email, but I continue getting the error : Runtime error 2501 on this line :

DoCmd.OutputTo acOutputReport, PurchaseOrderReport, acFormatPDF, filepath

I'm not sure what is causing this error as the information is moved along all the way to the line above.

Any thoughts on what could be causing this issue? I had initially this code in a module, and calling it from the email button, I was getting the same error.

Code:
Dim filepath As String
Dim oOutlook As New Outlook.Application
Dim oEmailItem As Outlook.MailItem
Dim filename As String

    If IsNull(DLookup("[PurchaseOrderID]", "[tblPurchaseOrder]", "[PurchaseOrderID]=" & Me.PurchaseOrderID.Value)) Then
        MsgBox "Purchase order number not found.", vbInformation
        Exit Sub
    Else
        PurchaseOrderReport = "rptPurchaseOrder"
        filename = "PurchaseOrder_" & Me.PurchaseOrderID.Value
        filepath = "C:\" & filename & ".pdf"
        DoCmd.OpenReport PurchaseOrderReport, acViewPreview, , "[PurchaseOrderID]=" & Me.PurchaseOrderID.Value, acHidden
        DoCmd.OutputTo acOutputReport, PurchaseOrderReport, acFormatPDF, filepath
        If oOutlook Is Nothing Then
            Set oOutlook = New Outlook.Application
        End If
        Set oEmailItem = oOutlook.CreateItem(olMailItem)
        With oEmailItem
           .Subject = "Purchase Order no. : " & Me.PurchaseOrderID.Value
           .Attachments.Add filepath
           .Display
        End With
        Set oEmailItem = Nothing
        Set oOutlook = Nothing
        'delete temp quote
        Kill filepath
        DoCmd.Close acReport, "rptPurchaseOrder"
    End If

Thank you in advance.

Rick
 

RickHunter84

Registered User.
Local time
Today, 08:14
Joined
Dec 28, 2019
Messages
85
Hello there,

I'm trying to print a report into a PDF file to later attached it to an email, but I continue getting the error : Runtime error 2501 on this line :

DoCmd.OutputTo acOutputReport, PurchaseOrderReport, acFormatPDF, filepath

I'm not sure what is causing this error as the information is moved along all the way to the line above.

Any thoughts on what could be causing this issue? I had initially this code in a module, and calling it from the email button, I was getting the same error.

Code:
Dim filepath As String
Dim oOutlook As New Outlook.Application
Dim oEmailItem As Outlook.MailItem
Dim filename As String

    If IsNull(DLookup("[PurchaseOrderID]", "[tblPurchaseOrder]", "[PurchaseOrderID]=" & Me.PurchaseOrderID.Value)) Then
        MsgBox "Purchase order number not found.", vbInformation
        Exit Sub
    Else
        PurchaseOrderReport = "rptPurchaseOrder"
        filename = "PurchaseOrder_" & Me.PurchaseOrderID.Value
        filepath = "C:\" & filename & ".pdf"
        DoCmd.OpenReport PurchaseOrderReport, acViewPreview, , "[PurchaseOrderID]=" & Me.PurchaseOrderID.Value, acHidden
        DoCmd.OutputTo acOutputReport, PurchaseOrderReport, acFormatPDF, filepath
        If oOutlook Is Nothing Then
            Set oOutlook = New Outlook.Application
        End If
        Set oEmailItem = oOutlook.CreateItem(olMailItem)
        With oEmailItem
           .Subject = "Purchase Order no. : " & Me.PurchaseOrderID.Value
           .Attachments.Add filepath
           .Display
        End With
        Set oEmailItem = Nothing
        Set oOutlook = Nothing
        'delete temp quote
        Kill filepath
        DoCmd.Close acReport, "rptPurchaseOrder"
    End If

Thank you in advance.

Rick
Hello,

i realized what it was. the C
Hi Rick. Can you show us what is in filepath?
Hello DBguy,

I realized what it was. Apparently, I cant write the file temporally in the C:\ drive - I switched the path to my C:\Documents\ - and it worked.

thank you :)

Rick
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:14
Joined
May 7, 2009
Messages
19,175
do you have Rights to create a file on the root drive (c:\)?
 

Users who are viewing this thread

Top Bottom