RickHunter84
Registered User.
- Local time
- Yesterday, 22:42
- 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.
Thank you in advance.
Rick
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