Need late binding syntax for emailing in Microsoft Access VBA.

Need late binding syntax for the following code.
Currently I have a bunch of people with different versions of Microsoft Access and need to late-bind:
Anyone to try and tackle this I appreciate it - or if anyone has a better version that doesn't use CDO - that would be great too!

Public Function SendEmailReport(sReportName, sFromName As String, sFromEmail As String, sToEmail As String) As Boolean

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

  'test email sending to ... so it doesn't go to Jim until he sees the coding piece of it.
  sToEmail = ""

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

  'Email the results of the report generated
  Set oEmail = oApp.CreateItem(olMailItem)
  With oEmail
      .Recipients.Add sToEmail
      .Subject = "RE: Timesheet for " & sFromName
      .Body = "Please review timesheet for Week: " & " Approval for: " & sFromName
      .Attachments.Add fileName
  End With

  bSuccess = True


  SendEmailReport = bSuccess
  Exit Function

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

End Function

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
With Late Binding you essentially use Object instead of the actual Object name:

Dim oApp As Object ' New Outlook.Application
Dim oEmail As Object 'Outlook.MailItem

You'd then create the items:

Set oApp = CreateObject("Outlook.Application")

You'd also have to either include your Constants, or use the actual value. For example, the value of olMailItem is 0, so you'd do this:

Dim olMailItem As Integer
olMailItem = 0

Or you could just use the value of 0 instead:

Set oEmail = oApp.CreateItem(0)

Finally, you'd remove the reference to the Outlook library.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stephenlecomptejrAuthor Commented:
Thank you so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.