Hi,
I have a problem with some code that I have copied & edited to suit my needs. Our company uses this code to email hundreds of statments of account to our customers. The problem is that when it hits an invalid email address such john_smith#gmail.com the error messafge appears and I have to figure where it had got to via the sent box. I then delete the records before that one tidy up that record (if known) and then start the run again with a reduced list.
What I would ideally like it to do is append each successful record to a table "Success" and the error records to a "Fail" table.
I have shown the code below and I am hoping that someone can help me with this problem.
Thanks in advance.
I have a problem with some code that I have copied & edited to suit my needs. Our company uses this code to email hundreds of statments of account to our customers. The problem is that when it hits an invalid email address such john_smith#gmail.com the error messafge appears and I have to figure where it had got to via the sent box. I then delete the records before that one tidy up that record (if known) and then start the run again with a reduced list.
What I would ideally like it to do is append each successful record to a table "Success" and the error records to a "Fail" table.
I have shown the code below and I am hoping that someone can help me with this problem.
Thanks in advance.
Code:
Private Sub Command1_Click()
Dim notesdb As Object
Dim notesdoc As Object
Dim notesrtf As Object
Dim notessession As Object
Dim strSupportEMail As String
Dim avarattach(3) As Variant
Dim rs As DAO.Recordset
Dim sql As String
Dim strPath As String
Dim x As String
x = 0
strPath = "C:\Temp\"
sql = "SELECT DISTINCT StatementTable.Terms, StatementTable.StateFile, StatementTable.Email, StatementTable.Salutation, StatementTable.SHD_ENDDATE FROM StatementTable;"
Set rs = CurrentDb().OpenRecordset(sql, dbOpenSnapshot)
Do While Not rs.EOF
StateFile = rs!StateFile
Email = rs!Email
Salutation = rs!Salutation
StateMonth = rs!SHD_ENDDATE
Terms = rs!Terms
x = x + 1
'make new mail message
Set notessession = CreateObject("Notes.Notessession")
Set notesdb = notessession.GetDatabase("", "")
Call notesdb.OPENMAIL
Set notesdoc = notesdb.CreateDocument
Call notesdoc.replaceitemvalue("Sendto", Email)
Call notesdoc.replaceitemvalue("Subject", "Statement of Account " & MonthName(Month(StateMonth)) & " " & Year(StateMonth))
Set notesrtf = notesdoc.CreateRichTextItem("body")
Call notesrtf.AppendText("Dear " & Salutation & ",")
Call notesrtf.AddNewLine(2)
Call notesrtf.AppendText("Please find attached your statement for " & MonthName(Month(StateMonth)) & " " & Year(StateMonth) & ".")
Call notesrtf.AddNewLine(2)
Call notesrtf.AppendText("The statement for the attached period where payments are recorded by Aon constitute a receipt and should be retained carefully.")
Call notesrtf.AddNewLine(2)
Call notesrtf.AppendText("The File - " & Terms & ".pdf" & " - contains additional supporting information and Terms & Conditions along with Bank Information.")
Call notesrtf.AddNewLine(2)
strSupportEMail = "someemail@email.com"
notesdoc.SaveMessageOnSend = True
Call notesdoc.Send(False) 'Send the email!
Set notessession = Nothing
rs.MoveNext
Pause (3) 'for a three second pause
Loop
MsgBox x & " Statement Emailed"
Set rs = Nothing
End Sub