Here is the code so far
I get an error on MailOutLook when it hits the .bodyformat
says it is missing or deleted....
I thought creating the object and declaring it 0 would be enough...
Code:
If IsNull(Me.txtBeforeDate) Or IsNull(Me.txtAfterDate) Then
MsgBox "You need to enter in a date range first"
Else
Const cstrPrompt As String = _
"Are you sure you want all the contacts in this list that have not yet been emailed? Yes/No"
If MsgBox(cstrPrompt, vbQuestion + vbYesNo) = vbNo Then
Cancel = True
ElseIf vbYes Then
'******************************** Start
Dim messagebody As String
Dim emsubject As String
Dim emailcont As String
Dim thecount As String
Dim mresponse As Integer
Dim emailofsc As String
Dim appOutLook As Object
Dim MailOutLook As Object
'check to see if Outlook is installed
On Error Resume Next
Set appOutLook = GetObject(, "Outlook.Application")
On Error GoTo 0
If appOutLook Is Nothing Then
Set appOutLook = CreateObject("Outlook.Application")
End If
Set MailOutLook = appOutLook.CreateItem(0)
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
'this moves from the first to the last record and counts them to a total.
rs.MoveFirst
rs.MoveLast
thecount = rs.RecordCount
If thecount <= 0 Then
Set rs = Nothing
Exit Sub
End If
mresponse = MsgBox("Are you sure you want to email " & thecount & " contacts?", vbYesNo, "Continue")
If mresponse = vbYes Then
AlternativeName = IIf(Me.SchoolTypeID = 3, " or the Director, ", IIf(Me.SchoolTypeID = 9, " ", " or the Principal,"))
TourOrganiserORPeter = IIf(Me.MergedNameT = Null, "Name" & vbCrLf & "Manager", Me.MergedNameT & vbCrLf & vbCrLf & "Tour Organiser") _
'############################################ this is the email message that gets sent ##################################
messagebody = "Dear " & Me.MergedName & AlternativeName _
& vbCrLf _
& vbCrLf _
& "This email is to remind you that " & Me.ShowTitle & " is booked to perform at" _
& vbCrLf & Me.SchoolName & " on " & Format(Me.BookingDate, "Long Date") & " at" _
& vbCrLf & Format(Me.ShowTime1st, "Medium Time") & " " & Format(Me.ShowTime2nd, "Medium Time") & " " & Format(Me.ShowTime3rd, "Medium Time") _
& vbCrLf _
& vbCrLf & "The Performer/s will arrive at the venue approximately " & Format(Me.SetUpTime, "h") & " hour & " & Format(Me.SetUpTime, "nn") & " minutes before the first performance and will need access to the venue at that time. The performance is approximately " & Format(Me.ShowLength, "h") & " hour & " & Format(Me.ShowLength, "nn") & " minutes and the performer/s will need approximately " & Format(Me.PackupTime, "h") & " hour & " & Format(Me.PackupTime, "nn") & " minutes after the performance to pack up." _
& vbCrLf _
& vbCrLf _
& "The performer/s will bring with them on the day a tax invoice and appraisal form." _
& vbCrLf _
& vbCrLf _
& "Thank you for including text in your year's activities and we trust you will all enjoy the event." _
& vbCrLf _
& vbCrLf _
& "Sincerely" _
& vbCrLf _
& vbCrLf _
& TourOrganiserORPeter _
& vbCrLf & "Text" & vbCrLf & "1Text" & vbCrLf & "Text" & vbCrLf & "00 000 000" & vbCrLf & "Email Text@email.com.au"
'####################################################################################################################################
emsubject = "Reminder of your performance on " & Me.BookingDate
rs.MoveFirst
Do Until rs.EOF
'Me.ConfirmationSent4th = -1
If IsNothing(rs![SchoolEmail]) Then
emailofsc = "noemail"
Else
emailofsc = rs![SchoolEmail]
End If
If emailofsc = "noemail" Then
'Me.ConfirmationSent4th = 0
rs.MoveNext
Else
'open Outlook, attach zip folder or file, send e-mail
With MailOutLook
.BodyFormat = 2
.To = "email@email.com.au"
''.cc = ""
''.bcc = ""
.Subject = msubject & " " & emailofsc
.HTMLBody = messagebody
.DeleteAfterSubmit = False 'This would let Outlook send the note without storing it in your sent bin
.ReadReceiptRequested = True
.send
End With
rs.MoveNext
End If
Loop
MsgBox "all done"
Else
MsgBox "You have cancelled emailing"
End If
rs.Close
Set rs = Nothing
End If
'******************************** End
End If