Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email problem

Status
Not open for further replies.

supermaestro

Programmer
Dec 18, 2002
15
0
0
GB
Hi. Can anybody who is an email expert see what is wrong with the following? I've put debugging code in this and know that it is going through the loop correctly and getting the email address from the query. However, when it has completed I check my mail boxes and nothing is being sent to them. Any ideas?

Private Sub mail_Click()
On Error Resume Next

Dim rs As New ADODB.Recordset
Dim sqlQuery As String
Dim strEMail As String
Dim strClient As String
Dim strMessage As String

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
'set recordset to your query
sqlQuery = "SELECT * FROM contacts WHERE contacts.[Account Type]='" & [Forms]![General Email]![Account Type] & "';"
Set rs = CurrentProject.Connection.Execute(sqlQuery)

Do While Not rs.EOF

strEMail = rs.Fields("Email")
strMessage = Me!message
strSubject = Me!subject

With objEmail
.To = strEMail 'client email address taken from the query
.subject = strSubject 'email subject
.Body = strMessage 'uses normal plain text. This is your personalized
'message that was created above
.Send 'sends email
End With

'move to the next record in the query

rs.MoveNext
Loop


MsgBox "All Emails Have Been Sent"

rs.Close

Set objEmail = Nothing
objOutlook.Quit
Set objOutlook = Nothing
End Sub
 
You may want to try copying and pasting a few of your email addresses into outlook to ensure that it recognizes the email addresses. Sometimes the settings in Outlook have to be changed.
EG - multiple email addresses can be separated by a comma or a colon.
 
If I display the email i.e. use .Display instead of .Send then Outlook comes up fine with the correct Fields filled in. However, I would like to send out a single email for Each recipient without calling .Display but just by sending them out automatically without the user seeing the Mail Client. Any ideas?
 
the .Display brings up Microsoft Outlook but the Email Client we use is Outlook Express. What's the best method for sending out using Outlook Express
 
Personally I'd change
Code:
 On Error Resume Next
to

Code:
On Error GoTo Err_Mail_Click
Your code
Code:
Exit Sub

Err_Mail_Click:
MsgBox Err.Number & " " & Err.Description

End Sub

That way you'll hopefully find out what's not working.

Sharon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top