docmd sendobject email

bbrendan

Registered User.
Local time
Today, 11:22
Joined
Oct 31, 2001
Messages
35
Hi All,

Im hoping someone can shed some light on this problem im having with sending a mass email.

What I have done is create a piece of code that queries a table containing around 20-30 records. This table holds customer details and email addresses.

When I hit the go button, the program only send off 1-2 emails... maybee three at tops at a go. It doesnt send any other after that. The only way I can get it to send more is to exit access then go back in and run the program again..

I would like it to send all the emails from the table in a loop. But it just stops after two or three....

any ideas would be greatfull

thanks
brendan


code
---------------------------------
Private Sub cmd_send_emails_Click()


' ####################################################################
' #
' # This gets the selected email address for firing off
' #

Dim rsEmail As DAO.Recordset 'the recordset with the email addresses to be used
Dim strEmail As String 'the email address
Dim strMessage As String 'message to be sent
Dim strSubject As String 'subject of message
Dim strOrderNum As String 'the web order number
Dim intEmail_Sent As Boolean
Dim strBillFirstname As String
Dim strBilllastname As String
Dim strShipFirstname As String
Dim strShipLastname As String
Dim strShipCompany As String
Dim strShipAddress As String
Dim strShipAddress2 As String
Dim strShipCity As String
Dim strShipProvince As String
Dim strShipPostalCode As String
Dim strShipCountry As String
Dim IntPlatinumOrder As Integer
Dim intCount As Integer


Set rsEmail = CurrentDb.OpenRecordset("w_imp_email") 'opens table with email addresses
On Error Resume Next 'skips email addresses with errors

Do While Not rsEmail.EOF 'loops through until the end of the table
strEmail = rsEmail.Fields("billemail").Value 'sets email address value
strOrderNum = rsEmail.Fields("OrderID").Value 'sets job number value
strBillFirstname = rsEmail.Fields("BillFirstName").Value
strBilllastname = rsEmail.Fields("BilllastName").Value
strShipFirstname = rsEmail.Fields("ShipFirstname").Value
strShipLastname = rsEmail.Fields("ShipLastname").Value
strShipCompany = rsEmail.Fields("ShipCompany").Value
strShipAddress = rsEmail.Fields("ShipAddress").Value
strShipAddress2 = rsEmail.Fields("ShipAddress2").Value
strShipCity = rsEmail.Fields("ShipCity").Value
strShipProvince = rsEmail.Fields("ShipProvince").Value
strShipPostalCode = rsEmail.Fields("ShipPostalCode").Value
strShipCountry = rsEmail.Fields("ShipCountry").Value
IntPlatinumOrder = rs.Email.Fields("Platinum_Order_No").Value


' ########### This is the email message text ###########

strSubject = "jogbloggs LTD Shipping Notification. Your Refernence: (" & strOrderNum & ")"
strMessage = "Dear " & strBillFirstname & " " & strBilllastname & "," & vbCrLf & vbCrLf & "We are pleased to advise you that your order: (" & strOrderNum & ") has been shipped to the following address:" _
& vbCrLf & vbCrLf & "-----------------------------------------" _
& vbCrLf & vbCrLf & " " & strShipFirstname & " " & strShipLastname & vbCrLf & " " & strShipCompany & vbCrLf & " " & strShipAddress & vbCrLf & " " & strShipAddress2 & vbCrLf & " " & strShipCity & vbCrLf & " " & strShipProvince & vbCrLf & " " & strShipPostalCode & vbCrLf & " " & strShipCountry & vbCrLf & vbCrLf & vbCrLf & "-----------------------------------------" _
& vbCrLf & " via standard postal services" & vbCrLf & "-----------------------------------------" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & " jogbloggs LTD" & vbCrLf & " 10 jogbloggs " & vbCrLf & " NW1 VVV London" & vbCrLf & " United Kingdom" & vbCrLf & " ph:(020) 9999 4800" & vbCrLf & " fax:(020) 9999 4828" & vbCrLf & " email:jogbloggs@blogg.co.uk" & vbCrLf & " http://www.jogbloggs.com"

intCount = rsEmail.RecordCount

DoCmd.SendObject , , , strEmail, , , strSubject, strMessage, False 'sends emails using above parameters
rsEmail.MoveNext 'goes to next record
Loop 'starts whole process over again
Set rsEmail = Nothing 'closes table
'End If
'DoCmd.Close 'closes form when completed

' this updates the history file to show that emails have been sent!

'DoCmd.RunSQL "UPDATE w_imp_email INNER JOIN w_imp_orders_history ON w_imp_email.OrderID = w_imp_orders_history.OrderID SET w_imp_orders_history.Email_Sent = Yes;"


Beep
MsgBox intCount & " Email(s) Sent" & _
vbCrLf & _
vbCrLf & _
"All emails sent!", vbInformation, "Email Notification"

End Sub
 
Try placing a breakpoint on the first line of code and step through to get a better idea of when the code stops sending emails. Since you have an On Error Resume Next statement as an error handler (bad idea, in my opinion) you may be skipping records that you think the emails are fine, but maybe something else is wrong. Try the step through approach, and then we can go from there.
 

Users who are viewing this thread

Back
Top Bottom