Compliation Error

KerryDee

Registered User.
Local time
Today, 13:24
Joined
Nov 24, 2016
Messages
36
Hi can any help me with this compilation error? I downloaded it to send an email with an attached report from Access 365 because the Docmd. SendObject was not working. I was getting 2293 error. Thank you very much for you help. I am a newbie.

Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim fileName As String, todayDate As String

'Export report in same folder as db with date stamp
todayDate = Format(Date, "MMDDYYYY")
fileName = Application.CurrentProject.Path & "\rptCarlsbad_" & todayDate & ".pdf"
DoCmd.OutputTo acReport, "rptCarlsbad", acFormatPDF, fileName, False

'Email the results of the report generated
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
.Recipients.Add "myemailaddress@email.com"
.Subject = "Water Testing Report"
.Body = "Attached is your Water Testing Report"
.Attachments.Add fileName
.Send
End With

MsgBox "Email successfully sent!", vbInformation, "EMAIL STATUS"

End Sub
 
I'm not getting a compile error when I compile this with Access 2013 (Office 365). I did have to add the Microsoft Outlook 15.0 Object Library reference. (VBA Editor, Tool, References). Have you done that?
 
Why can't you just use docmd.SendObject?
 
Last edited:
Hi ranman 256/pbaldy sneuberg/: Thanks for the quick response. I do not see the Microsoft Outlook 15.0 Object Library reference. I do see the Microsoft Outlook 16.00, which I checked off but the code is not working . I am running Access 2016 (365). Also, the code I posted in my first message was because this code which I previously used in Office 2010 was not working after upgrading to Access 2016 (365). I kept getting the 2293 code with the "Microsoft Access cannot send this email."

Private Sub btnEmailReport_Click()
Dim strReport As String
strReport = "rptCarlsbad"
Me.Refresh
DoCmd.OpenReport strReport, acViewPreview, , "ID=" & Me!ID
Reports(strReport).Visible = True
DoCmd.SendObject acSendReport, strReport, acFormRTF, , , , "For your information"
DoCmd.Close acReport, strReport
End Sub
 
If you change this line
Code:
DoCmd.SendObject acSendReport, strReport, [COLOR="blue"]acFormRTF[/COLOR], , , , "For your information"

to

Code:
DoCmd.SendObject acSendReport, strReport, [COLOR="Blue"]acFormatRTF[/COLOR], , , , "For you information"
in the code it runs ok on my system (Access 2013) but the error in the Output Format argument causes a compilation error not the 2293 error. I suggest looking for problems in the Outlook installation. Can you send email directly from Outlook?

If it's not a configuration issue I suggest trying a repair of the Office 365 application. If you open the Control Panel, click on Uninstall a program, right click on Microsoft Office 365, and click change you will see the repair options
 
sneuberg: Thanks you were correct!! I used msn as my email instead of outlook and the corrected code you provided works perfectly. So I am going to have to figure out what is wrong with outlook, as I used the repair of Office 365 application but Access did not send the email via outlook.
 

Users who are viewing this thread

Back
Top Bottom