开发者

Sending Outlook email using Access VBA

开发者 https://www.devze.com 2023-03-17 07:51 出处:网络
This code is working in another Acce开发者_运维技巧ss db. I just copy pasted the code but there is an error in the first line.

This code is working in another Acce开发者_运维技巧ss db.

I just copy pasted the code but there is an error in the first line.

Public Function sendEmailOutlook()

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

On Error GoTo ErrHandler:
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

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

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("sads")
'Set objOutlookRecip = .Recipients.Add("niticin@gmail.com")
objOutlookRecip.Type = olTo

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an automatic confirmation"
.Body = "This is a confirmation of the" & Form_Booking.Event_Name.Value & vbCrLf & _
    "Client: " & Form_Booking.FirstName.Value & vbCrLf & vbCrLf & _
    "Start Time: " & Form_Booking.Actual_Start_Time.Value
.Importance = olImportanceHigh  'High importance
.Save
.Send
    
End With
'Set objOutlookMsg = Nothing
Set objOutlook = Nothing

Exit Function

ErrHandler:
    MsgBox ("Make sure your Outlook is active and configured!")
End Function

Error on line

Dim objOutlook As Outlook.Application

compiler : user defined type not defined.


You're using early binding, so in the VBA Editor you need to click Tools -> References & tick Microsoft Outlook ?? Object Library in order to expose Outlook's object model to your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号