Hi there, I am new to
VB and am trying to execute the VBA in Chapter 10, however I receive a runtime error stating the module used in this statement cannot be found:
Set objEmail = objOutlook.CreateItem(olMail)
I've set my references to use MS Outlook library so I don't know what the issue could be. Does anyone have any idea?
Here's the script :
Sub ControlOutlook()
Dim objOutlook As New Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strLtrContent As String
Dim rsContacts As New ADODB.Recordset
rsContacts.ActiveConnection = CurrentProject.Connection
rsContacts.Open "tblContacts"
'for each record in the tblContacts table, send an email
Do While Not rsContacts.EOF
strLtrContent = "Dear " & rsContacts("FirstName") & " "
strLtrContent = strLtrContent & rsContacts("LastName") & ":" & vbCrLf & vbCrLf
strLtrContent = strLtrContent & "Please note we have moved to a new location. "
strLtrContent = strLtrContent & "Our new address is 4 Somewhere, Avon, IN 46060."
strLtrContent = strLtrContent & vbCrLf & vbCrLf & "Sincerely," & vbCrLf & vbCrLf
strLtrContent = strLtrContent & "Your Favorite Store"
'create an email regarding the new business location
Set objEmail = objOutlook.CreateItem(olMail)
objEmail.Recipients.Add rsContacts("Email")
objEmail.Subject = "Our address has changed."
objEmail.Body = strLtrContent
'send the message
objEmail.Send
'move to the next contacts record
rsContacts.MoveNext
Loop
End Sub