I've seen several things that should be fixed:
Some Naming suggestions:
-----------------------------
Use only letters and numbers (exception is the underscore) for object names.
Do not use spaces, punctuation or special characters in object names.
Do not begin an object name with a number.
Do not use Look up FIELDS, multi-Value fields or Calculated fields in tables.
================================================== ==================
IMPORTANT:
Code:
Option Compare Database '<<-- These two lines should be at the top of EVERY code module!!
Option Explicit '<<-- These two lines should be at the top of EVERY code module!!
================================================== ==================
Error in declarations:
Code:
Dim v1, v2, v3, v4, v5, v6, v7, v8 As Integer '<<- only v8 is defined as Integer - all others are Variants
Dim val1, val2, val3 As Integer '<<- only val3 is defined as Integer - others are Variants
Dim search1, search2 As String '<<- only search2 is defined as String - others are Variants
You must explicitly declare each variable
Code:
Dim v1 As Integer, v2 As Integer, v3 As Integer, v4 As Integer, v5 As Integer, v6 As Integer, v7 As Integer, v8 As Integer
================================================== ==================
Should NEVER have declarations inside of a loop!!
Code:
Private Sub BulkEmail1()
'crazypants
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qry_second_contact", dbOpenForwardOnly)
Do
Dim mailItem As Outlook.mailItem '<<-- Should NEVER have declarations inside of a loop!!
initoutlook
Dim outlookApp As Outlook.Application'<<-- Should NEVER have declarations inside of a loop!!
Set outlookApp = CreateObject("Outlook.Application") '<<-- Need to Close Outlook and Set outlookApp = Nothing just before "END SUB"
Set mailItem = outlookApp.CreateItem(olMailItem) '<<-- Need to have Set outlookApp = Nothing just before "END SUB"
' Dim Attach as Outlook.Attachments
mailItem.SentOnBehalfOfName = "sofc@stuact.tamu.edu"
mailItem.To = rs.Fields("Primary Advisor - E-mail") & "; " & rs.Fields("Secondary Advisor - E-mail") & "; " & rs.Fields("Chief Student Leader - E-mail") & "; " & rs.Fields("Treasurer - E-mail")
'mailItem.CC = "email"
mailItem.Subject = "Follow up re: Ticket#: " & rs.Fields("IncidentID") & " Student Organization Finance Center - " & rs.Fields("OrganizationName")
mailItem.Display
' mailItem.Attachments.Add "\\innovation\CustomerProjects\Dunkin\Support\Dunkin Documents\DMB Install Date Assignment Memo.pdf"
mailItem.BodyFormat = olFormatHTML
'Begin Text
mailItem.HTMLBody = "<HTML><p>Howdy!</p><p>We have been unable to complete your request for $" & CCur(rs.Fields("Dollar Amount")) & " payable to " & rs.Fields("Payableto") & " due to the following deficiency: </p><p><b>" & rs.Fields("ErrorType") & "</b></p><p> Initially communicated on " & rs.Fields("DateStamp") & ". Please contact the SOFC to resolve this ticket. This request will be returned unprocessed to the organization mail slot on " & rs.Fields("ReturnDate") & ". </p><p>This information has been sent using a new automated process. If you believe this notice to be in error, please respond by email or call with the ticket #. This notificaiton is automated. Thank you for your assistance in resolving this matter." & _
"<b><p><span style='font-size:9.0pt;font-family: ""Arial"",sans-serif;color:#262626'>SOFC Business Management</b><br/>Department of Student Activities | Texas A&M University<br/><span style='font-size:9.0pt;font-family:""Arial"",sans-serif;color:#262626'>Student Organization Finance Center<br/>235 John J. Koldus Building. 1236 TAMU | College Station, TX 77843-1236<br/><span style='font-size:9.0pt;font-family:""Arial"",sans-serif;color:#262626'>ph. 979.845.1114 | fax. 979.862.8166 | <a href=""mailto:sofc@stuact.tamu.edu"">sofc@stuact.tamu.edu</a></span><br/><span style='font-size:9.0pt;font-family:""Arial"",sans-serif;color:black;background:white'>" & _
"- - - - - - - - - - - - - - - - - - - - - - - - </span><span style='font-size:9.0pt;font-family:""Arial"",sans-serif;color:black'><br></span><span style='font-size:9.0pt;font-family:""Arial"",sans-serif;color:#262626'><br></span><b><span style='font-size:9.0pt;font-family:""Arial""," & _
"sans-serif;color:#632423'><a href=""http://studentactivities.tamu.edu/""><span style='color:#632423'>http://studentactivities.tamu.edu/</span></a> </span></b><span style='font-size:9.0pt;font-family:""Arial"",sans-serif'>| <a href=""http://www.facebook.com/stuact""><span style='color:windowtext'>www.facebook.com/stuact</span></a> | <a href=""http://www.twitter.com/tamustuact""><span style='color:windowtext'>www.twitter.com/tamustuact</span></a><b><span style='color:#632423'><p></p></span></b></span></p><p class=MsoNormal><p> </p></p></div></body></html>"
' End Text
mailItem.Send
rs.MoveNext
Loop Until rs.EOF
rs.Close
Set rs = Nothing
Set mailItem = Nothing
End Sub
================================================== ==================
In the tables "tbl_Cashiers" and "tbl_ErrorIncident", there is a field named "DateTimeStamp", with the Default Value property set to "Now()".
You should not have "Now() AS DateTimeStamp" in the Append queries!