Hi
Has anyone experienced the following problem - I've set up a piece of VBA code to loop through and email various recipients data, in the form of records within the email body. This works fine, but occasionally produces an error whereby the email output body lines are duplicated spuriously. This only seems to happen when running a large number of email loops.
The data source for the email body content is a table, which for each 'loop' is refreshed with new data by 1) deleting records from that table, and then 2) appending data to the table.
The portion of code for the loop & email:
Do
'Build outputbodytext
DoCmd.OpenQuery ("EmailQ2")
DoCmd.OpenQuery ("EmailQ1")
'set up email
Set rec2 = CurrentDb.OpenRecordset("outputbodytext")
strSendTo = rec2("Email")
strTo = rec2("Email")
strcc = ""
Set olApp = CreateObject("Outlook.application")
Set olItem = olApp.createitem(olMailTem)
olItem.Display
olItem.To = strTo
olItem.cc = strcc
olItem.Body = "Remittance Advice - details as follows: "
olItem.Subject = "Remittance Advice"
Set rec = CurrentDb.OpenRecordset("OutputBodyText")
If Not (rec.BOF And rec.EOF) Then
rec.MoveLast
rec.MoveFirst
intCount = rec.RecordCount
'loop lines within table
For intLoop = 1 To intCount
olItem.Body = olItem.Body & rec("txt") & Chr(1)
rec.MoveNext
Next intLoop
End If
With olItem
.send
End With
Me.currentkey = Me.currentkey + 1
Loop Until Me.currentkey = Me.Maxrecord + 1
MsgBox "Completed"
Set olApp = Nothing
Set olItem = Nothing
Best regards
Has anyone experienced the following problem - I've set up a piece of VBA code to loop through and email various recipients data, in the form of records within the email body. This works fine, but occasionally produces an error whereby the email output body lines are duplicated spuriously. This only seems to happen when running a large number of email loops.
The data source for the email body content is a table, which for each 'loop' is refreshed with new data by 1) deleting records from that table, and then 2) appending data to the table.
The portion of code for the loop & email:
Do
'Build outputbodytext
DoCmd.OpenQuery ("EmailQ2")
DoCmd.OpenQuery ("EmailQ1")
'set up email
Set rec2 = CurrentDb.OpenRecordset("outputbodytext")
strSendTo = rec2("Email")
strTo = rec2("Email")
strcc = ""
Set olApp = CreateObject("Outlook.application")
Set olItem = olApp.createitem(olMailTem)
olItem.Display
olItem.To = strTo
olItem.cc = strcc
olItem.Body = "Remittance Advice - details as follows: "
olItem.Subject = "Remittance Advice"
Set rec = CurrentDb.OpenRecordset("OutputBodyText")
If Not (rec.BOF And rec.EOF) Then
rec.MoveLast
rec.MoveFirst
intCount = rec.RecordCount
'loop lines within table
For intLoop = 1 To intCount
olItem.Body = olItem.Body & rec("txt") & Chr(1)
rec.MoveNext
Next intLoop
End If
With olItem
.send
End With
Me.currentkey = Me.currentkey + 1
Loop Until Me.currentkey = Me.Maxrecord + 1
MsgBox "Completed"
Set olApp = Nothing
Set olItem = Nothing
Best regards