Hi Guys
i have this code that runs on the "On Click" event of a button
Code:
'This Command Opens the report in hidden mode so that the calculations work on the Report when it's output as a PDF
DoCmd.OpenReport "rptCustomerStatement", acViewPreview, "", "", acHidden
DoCmd.OutputTo acOutputReport, "rptCustomerStatement", acFormatPDF, (DLookup("FilePath", "tblCompanyDetails", "CompanyID = 1")) & "\customers" & "\" & Me.Full_Name & "\Statements" & "\" & (DLookup("[companyname]", "tblCompanyDetails", "CompanyID = 1")) & " Customer Statement" & " " & Format(Date, "dd-mm-yyyy") & ".pdf"
Dim OlApp As Object
Dim objMail As Object
On Error Resume Next 'Keep going if there is an error
Set OlApp = GetObject(, "Outlook.Application") 'See if Outlook is open
If Err Then 'Outlook is not open
Set OlApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook
End If
'Create e-mail item
Set objMail = OlApp.CreateItem(olMailItem)
With objMail
'Set body format to HTML
.BodyFormat = olFormatHTML
.To = Me.E_Mail.Value
.Subject = "Customer Statement Attached as of" & " " & Format(Date, "dddd d mmmm yyyy")
.HTMLBody = "Dear" & " " & Me.Full_Name.Value & " " & Me.Email_Statement_text.Value
.Attachments.Add (DLookup("FilePath", "tblCompanyDetails", "CompanyID = 1")) & "\customers" & "\" & Me.Full_Name & "\Statements" & "\" & (DLookup("[companyname]", "tblCompanyDetails", "CompanyID = 1")) & " Customer Statement" & " " & Format(Date, "dd-mm-yyyy") & ".pdf"
.Display
End With
Set OlApp = Nothing
Set objMail = Nothing
DoCmd.Close acReport, "rptCustomerStatement", acSaveYes
Me.Sent_Date = Date
This works really well and attaches the report to the e-mail as an attachment
However, what i would really like to do is to change the code so that i do not need a reference adding to the "Tools - references" section of the VBA IDE
I know their is early and late binding, im not sure which this uses and what i need to change
we have different versions of outlook installed on some computers and i was looking for a better way of doing things
once again
many thanks
Steve