Error Sending Email Through Access - Via VBA

CarlRostron

Registered User.
Local time
Today, 05:18
Joined
Nov 14, 2011
Messages
88
I have tried both early & late binding. There must be something wrong here somewhere I am convinced the code is correct:

Code:
Option Explicit
Sub EmailClient()
   Dim objOutlook As Object
   Dim objOutlookMsg As Object
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment
   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")
   ' Create the message.
   Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
   With objOutlookMsg
 
        'DO HERE
 
   End With
   Set objOutlookMsg = Nothing
   Set objOutlook = Nothing
End Sub

Attached are the references I have set.

I either get the 'ActiveX component can't create object' error with the above code, or if I use early binding I get a type mismatch error on line:
Code:
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

Please help.
 

Attachments

  • References.png
    References.png
    40.4 KB · Views: 111
Last edited:
With late binding Access has no clue what olMailItem is. It is an integer, probably 0 or 1 -google it.
 
You made that sound so easy :-)

Resolved, thanks for your help!!
 
Hi can i ask how you resolved it as i am having the same problem, worked fine on all my computers and then out of blue stopped working on two and only works on one computer now and i cant find solutions
 
Code:
Private Sub cmdEmail_Click()
   Dim objOutlook As Outlook.Application
   Dim objOutlookMsg As Object
   Dim objOutlookRecip As Outlook.Recipient
   Dim objOutlookAttach As Outlook.Attachment

   ' Create the Outlook session.
   Set objOutlook = New Outlook.Application

   ' Create the message.
   Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

   If (Me.[Email] <> "") Then
     With objOutlookMsg
       .To = Me.[Email]
       .Display
     End With
   Else
     MsgBox "To email this Client, please insert an email address for them.", vbInformation, "Unable to Send Email"
   End If
   
   Set objOutlookMsg = Nothing
   Set objOutlook = Nothing
End Sub

Please try this.
 

Users who are viewing this thread

Back
Top Bottom