Hi.
I used this forum to create this code in order to send an e-mail confirmation to clients who have placed orders. My goal is to send a bulk e-mail to all of those who appear in the query results. I created a form which displays each record individually but I really want the e-mail to be sent to everyone in the query result. Nonetheless, this is the code I am using behind the button on the form. I get a "compile error: user-defined type not identified" error but when I try to set the reference (>tools >references) "references" is greyed out.
Private Sub Command28_Click()
'******begin code******
Dim email, ref, origin, destination, notes As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
email = Me!ContactEmail
OrderID = Me!OrderID
TrackingNumber = Me!TrackingNumber
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'***creates and sends email
With objEmail
.To = email
.Subject = ref & " " & origin & " " & destination
.Body = notes
.Send
End With
'**closes outlook
Set objEmail = Nothing
objOutlook.Quit
Exit Sub
'****end code****
End Sub
#1 I need help with the error message
#2 Am I going about this the right way? Each e-mail will have a different body. Should I export the data to a fixed location on the server and have my users simply do a mail merge?
I would like as few steps as possible...one click of a button is always best for them.
Thanks.
Heather
I used this forum to create this code in order to send an e-mail confirmation to clients who have placed orders. My goal is to send a bulk e-mail to all of those who appear in the query results. I created a form which displays each record individually but I really want the e-mail to be sent to everyone in the query result. Nonetheless, this is the code I am using behind the button on the form. I get a "compile error: user-defined type not identified" error but when I try to set the reference (>tools >references) "references" is greyed out.
Private Sub Command28_Click()
'******begin code******
Dim email, ref, origin, destination, notes As String
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
email = Me!ContactEmail
OrderID = Me!OrderID
TrackingNumber = Me!TrackingNumber
'***creates an instance of Outlook
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'***creates and sends email
With objEmail
.To = email
.Subject = ref & " " & origin & " " & destination
.Body = notes
.Send
End With
'**closes outlook
Set objEmail = Nothing
objOutlook.Quit
Exit Sub
'****end code****
End Sub
#1 I need help with the error message
#2 Am I going about this the right way? Each e-mail will have a different body. Should I export the data to a fixed location on the server and have my users simply do a mail merge?
I would like as few steps as possible...one click of a button is always best for them.
Thanks.
Heather