Error 2501 - The OutputTo action was canceled (1 Viewer)

PatAccess

Registered User.
Local time
Today, 14:33
Joined
May 24, 2017
Messages
284
Good day all my smart people,

Here is my code:

Private Sub cmdEmailRpt_Click()
Dim FileName As String
Dim FilePath As String
Dim oOutlook As Outlook.Application
Dim oEmailItem As MailItem

'Save the report as a pdf file to a folder
FileName = Me.cboAdmin.Column(1) & Date
FilePath = "P:\Internal\Integration\Arlette\Licensing\Corporate\Certificates" & FileName & ".pdf"
'Create temporary file
DoCmd.OutputTo acOutputReport, "Rpt_MissingCert", acFormatPDF, FilePath
'Create the email
If oOutlook Is Nothing Then
Set oOutlook = New Outlook.Application
End If
Set oEmailItem = oOutlook.CreateItem(olMailItem)
With oEmailItem
.To = Me.txtEmail
.Subject = "RMF Licensing Database - Missing Certificates"
.Body = "Hello" & Me.txtFirstName & vbNewLine & vbNewLine & _
"I hope this email finds you and your family well!" & vbNewLine & _
"I need all PE's certificates at this time. Please see the attached report for your team missing certifcate." & vbNewLine & _
"Also, if I am missing any current PE within your office please submit them as well" & vbNewLine & _
"You can drop all certificates in this folder: H:\Standards\Stds Development\Licensing" & vbNewLine & vbNewLine & _
"Feel free to contact me with any question and/or comments" & vbNewLine & vbNewLine & _
"Thank you so much for your help!"
.Attachments.Add FilePath
.Display
End With

Set oEmailItem = Nothing
Set oOutlook = Nothing
'Delete temporary file
'Kill FilePath


End Sub

When I run it, I get Error 2501 - The OutputTo action was canceled - I've read some of the answers on another forum but no resolution. Is it something in my preference options?

What am I missing?:banghead:

Thank you for your help
 

GinaWhipp

AWF VIP
Local time
Today, 14:33
Joined
Jun 21, 2011
Messages
5,901
Hmm, you are attaching a Date() to the file name. Thinking that's the problem with back slashes and all. Does it work if you remove the Date()? If yes, then you will need to reformat the Date() to either exclude the slashes or use periods instead of slashes.
 

PatAccess

Registered User.
Local time
Today, 14:33
Joined
May 24, 2017
Messages
284
OMG That was exactly the problem. but how what if I want the date to appear at the end of my FilePath. Should I write like:
FilePath = "P:\Internal\Integration\Arlette\Licensing\Corporate\Certificates" & FileName & Date & ".pdf"

or how should I implement the Date()
 

Eljefegeneo

Still trying to learn
Local time
Today, 11:33
Joined
Jan 10, 2011
Messages
904
Just my two cents, but I had similar problems. Solve it with using the following:

Code:
myFile = Format(Date, "MMDYYYY") & " " & myQry & ".xlsx"
Since I set the format of the date, I haven't had a problem. You could try setting the format of the date you want and test it. Should work.
 

GinaWhipp

AWF VIP
Local time
Today, 14:33
Joined
Jun 21, 2011
Messages
5,901
Oh, you got a solution that should work perfectly.
 

PatAccess

Registered User.
Local time
Today, 14:33
Joined
May 24, 2017
Messages
284
Thank you Guys it's all working now. I formatted the date as suggested. You guys rock!
 

Mark_

Longboard on the internet
Local time
Today, 11:33
Joined
Sep 12, 2017
Messages
2,111
While working, you may wish to choose a different format for the date. YYYYMMDD gives sequential dates. MMDYYYY will give you in month order.

As this is for a selected value FIRST, then date, you may find it less than useful to have all of January 1983 before the most recent.
 

Users who are viewing this thread

Top Bottom