I have 2 problems:
1. Upon execution, with the .Save command line, this code get's stuck in Outlook's Draft folder and does not get sent; however, .Send will only send the first recipient in the list
2. I would like to use the .From line (currently commented out), but this makes the entire code fail - with no error messages
Here's the code:
Private Sub Reminder_Click()
Dim rs As DAO.Recordset ' recordset of suppliers (for email address)
Dim objOutlook As Object ' outlook object
Dim objMessage As Outlook.MailItem ' outlook mail message
Dim strOrder As String ' string of order details
Dim objSafeMail As Object
On Error GoTo SendObject_Error
Set objOutlook = CreateObject("Outlook.Application")
Set rs = CurrentDb.OpenRecordset("SELECT* FROM qryEmail WHERE tblRegistrants.AddressID= " & Me!AddressID)
While Not rs.EOF
strOrder = "ENROLLMENT REMINDER" & _
vbCrLf & vbCrLf & _
"You are scheduled to attend the class on " & [CRSE] & " held " & [CourseDate] & " @ " & [StartOfCourse] & " - " & [EndOfCourse] & ". " & _
vbCrLf & vbCrLf & _
"IMPORTANT" & _
vbCrLf & _
"If for some reason you need to cancel, please reply to this email or call me @ (000) 000-000. Some classes have a waiting list and others may wish to take your spot. Please give them the opportunity to do so." & _
vbCrLf & vbCrLf & _
"Thank you." & _
vbCrLf & vbCrLf & _
vbCrLf & _
"Blagh" & _
vbCr & _
"Blah" & _
vbCr & _
"blah, Inc." & _
vbCr & _
"blah" & _
vbCr & _
"000-000-0000 Office"
If Not IsNull(rs("Email")) Then
Set objMessage = objOutlook.CreateItem(olMailItem)
With objMessage
.To = rs("Email")
'.From = "blah@gmail.com"
.Subject = "ENROLLMENT REMINDER ! - " & [CRSE] & " on " & [CourseDate] & ""
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY><FONT face=Verdana><FONT size=2><STRONG><U>ENROLLMENT REMINDER</STRONG></U><BR><BR>You are scheduled to attend the class on <FONT color=#0000ff><b>" & [CRSE] & "</FONT></B> held <FONT color=#0000ff><b>" & [CourseDate] & "</FONT></B> @ " & [StartOfCourse] & " - " & [EndOfCourse] & ".<BR><BR><STRONG><U>IMPORTANT</U></STRONG><BR>If for some reason you need to cancel, please reply to this email or call me @ (000) 000-0000. Some classes have a waiting list and others may wish to take your spot. Please give them the opportunity to do so.<BR><BR>Thank you.<BR><BR><BR><B>blah<BR><U>lah</U></B><BR>blah, Inc.<BR>blag<BR>(000) 000-0000 Office</FONT></BODY></HTML>"
.Importance = olImportanceHigh 'High importance
.Save
End With
End If
Set objSafeMail = CreateObject("Redemption.SafeMailItem")
objSafeMail.Item = objMessage
'Send
objSafeMail.Send
rs.MoveNext
Wend
' tidy up
rs.Close
Set rs = Nothing
Set objOutlook = Nothing
Set objMessage = Nothing
SendObject_Error:
If Err.Number = 2501 Then
MsgBox "You have cancelled the e-mail; thus, it was not sent.", vbInformation, "Notice!"
End If
End Sub
ASKER
However, I will still provide the 500 points if someone can tell me why the from line doesn't work, and how can i get it to work?
Additional infor that might help. I have two email accounts tied to my Outlook account. One is my personal company account (set as the default in Outlook), the second is my department's general email address. I would like to use the latter for the code above. Why doesn't it work?