Link to home
Start Free TrialLog in
Avatar of Brian Pierce
Brian PierceFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access 2010 VBA Problem

I am trying to impliment the follollowing Access VBA code from http://www.access-programmers.com/sending-an-email-out-from-access-2010.aspx

However, when I click the button to execute the code I get the following error - see attached pic -

Dim olApp As New Outlook.Application  - User defined type not defined

any suggestions how I get this to work ?



Code below:

Private Sub Command1_Click()


'Save report to local drive
 Dim strFile As String
 strFile = "c:\temp\RRL" & Me.BUNNum & Format(Now, "YYYYMMDD_hms") & ".pdf"
 DoCmd.OutputTo acOutputReport, "rptIndivIncident", acFormatPDF, strFile


Call SendEmailOutlook(Me.EngineerEmail, "RRL Incident Report", "Attached please find the Incident Report", strFile)

End Sub


Public Function SendEmailOutlook( _
 MsgTo As String, _
 MsgSubject As String, _
 MsgBody As String, _
 ReportPath As String)
 
' Get Outlook using the "New" keyword
 Dim olApp As New Outlook.Application
 Dim olMailItem As Outlook.MailItem
 
' Create a new email object
 Set olMailItem = olApp.CreateItem(0)
 
' Add the To/Subject/Body/Attachments to the message then send the message
 With olMailItem
 .To = MsgTo
 .Subject = MsgSubject
 .Body = MsgBody
 .Attachments.Add ReportPath
 .Send
 End With
 
Set olMailItem = Nothing
 Set olApp = Nothing
 
End Function
Avatar of Brian Pierce
Brian Pierce
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

I forgot to attach the pic - here it is
Capture.PNG
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Spot on - and fast too - Thanks