ChrisCalvert
Technical User
I, through a great deal of interaction here, have created a function that sends an email to all email addresses in a recordset. However, this seems to be randomly skipping people. Here is the code it uses:
---------------------------------------------
Private Sub SendBttn_Click()
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Dim strTextLine As String
Dim strTemplate As String
Dim myTextFile As New TextFile
Dim intError As Integer
strTemplate = ""
myTextFile.FileName = "r:\iwelctesttemp.txt"
myTextFile.StripLeadingSpaces = False
myTextFile.StripTrailingSpaces = False
intError = myTextFile.cfOpenFile
If intError = 0 Then
While Not myTextFile.EndOfFile
myTextFile.csGetALine
strTextLine = myTextFile.Text
strTemplate = (strTemplate + (Chr$(13))) + strTextLine
Wend
Else
MsgBox Error(intError)
End If
myTextFile.cfCloseFile
Set myTextFile = Nothing
Set rst = db.openrecordset("Select * from EmailsToday"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Cycle through the table, sending it to each person on the list
Do While Not rst.EOF
DoCmd.SendObject acSendNoObject, , acFormatRTF, rst!Email, , , "Welcome to SERVICE.", strTemplate, False
DoEvents
If Not rst.EOF Then
rst.MoveNext
End If
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
-----------------------------------------------
Now, I have conducted several trials, and the system seems to skip people when sending out email. It's not that they don't get them, I check the outlook 'sent items' and these are just not there.
I have results from some trials listed below. The best conjecture I have at this point is that it is somehow related to overloading something and my emails are just skipped. I cannot say for sure. Here is the trial data.
The names lised correspond to addresses in the table EmailsToday (from where this reads what to send).
------------------------------------------------------
Trial1
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Trial2a,b,c (same results 3 times)
Me-Sent
Chad-Sent
Donnie-Sent
Marissa- NOT SENT
Shontae- NOT SENT
Sharon- Sent
Pam- Sent
Trial3
Me-Sent
Marissa-Sent
Donnie-Sent
Chad-Sent
Sharon-Sent
Shontae- NOT SENT
Erika- NOT SENT
Trial4
Kevin-Sent
Shontae-Sent
Marissa-Sent
--------------------------------------------------------
I tried adding the do events in the loop, on the basis of my 'overload' guess. Well, ideas or suggestions would be looked upon with fervent thanks.
---------------------------------------------
Private Sub SendBttn_Click()
Dim db As DAO.Database, rst As DAO.Recordset
Set db = CurrentDb
Dim strTextLine As String
Dim strTemplate As String
Dim myTextFile As New TextFile
Dim intError As Integer
strTemplate = ""
myTextFile.FileName = "r:\iwelctesttemp.txt"
myTextFile.StripLeadingSpaces = False
myTextFile.StripTrailingSpaces = False
intError = myTextFile.cfOpenFile
If intError = 0 Then
While Not myTextFile.EndOfFile
myTextFile.csGetALine
strTextLine = myTextFile.Text
strTemplate = (strTemplate + (Chr$(13))) + strTextLine
Wend
Else
MsgBox Error(intError)
End If
myTextFile.cfCloseFile
Set myTextFile = Nothing
Set rst = db.openrecordset("Select * from EmailsToday"
'Cycle through the table, sending it to each person on the list
Do While Not rst.EOF
DoCmd.SendObject acSendNoObject, , acFormatRTF, rst!Email, , , "Welcome to SERVICE.", strTemplate, False
DoEvents
If Not rst.EOF Then
rst.MoveNext
End If
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
End Sub
-----------------------------------------------
Now, I have conducted several trials, and the system seems to skip people when sending out email. It's not that they don't get them, I check the outlook 'sent items' and these are just not there.
I have results from some trials listed below. The best conjecture I have at this point is that it is somehow related to overloading something and my emails are just skipped. I cannot say for sure. Here is the trial data.
The names lised correspond to addresses in the table EmailsToday (from where this reads what to send).
------------------------------------------------------
Trial1
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Me-Sent
Trial2a,b,c (same results 3 times)
Me-Sent
Chad-Sent
Donnie-Sent
Marissa- NOT SENT
Shontae- NOT SENT
Sharon- Sent
Pam- Sent
Trial3
Me-Sent
Marissa-Sent
Donnie-Sent
Chad-Sent
Sharon-Sent
Shontae- NOT SENT
Erika- NOT SENT
Trial4
Kevin-Sent
Shontae-Sent
Marissa-Sent
--------------------------------------------------------
I tried adding the do events in the loop, on the basis of my 'overload' guess. Well, ideas or suggestions would be looked upon with fervent thanks.