Email Question

Iwra

Registered User.
Local time
Today, 19:59
Joined
Jul 25, 2002
Messages
15
Hi I am trying to send an email to everyone on my database, upon searching the forum I found the following code but it throws an error "An expression you entered is the wrong data type for one of the arguements"

Private Sub CmdEmail_Click()
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Dim strBody As String
Set rsEmail = CurrentDb.OpenRecordset("QrySendEmails")

Do While Not rsEmail.EOF
strEmail = rsEmail.Fields("Email").Value
strBody = rsEmail.Fields("Body").Value
DoCmd.SendObject , , , strEmail, , , _
"SUBJECT", _
"MESSAGE", _
vbCrLf & vbCrLf & strBody _

rsEmail.MoveNext

Loop
Set rsEmail = Nothing

MsgBox "Emails have been sent"
End Sub

Does anyone have a suggestion for this?

Thanks
 
I resolved the above error. Now I'm trying to ad the name at the top of the email Hello ContactName then the body of the email underneath, this time I get an error saying "Arguement not optional"

Private Sub CmdEmail_Click()
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Dim strBody As String
Set rsEmail = CurrentDb.OpenRecordset("QrySendEmails")

Do While Not rsEmail.EOF
strEmail = rsEmail.Fields("Email").Value
strBody = rsEmail.Fields("Body").Value
DoCmd.SendObject , , , strEmail, , , _
"SUBJECT", _
hello & rsEmail.Fields = ("contactname"), _
vbCrLf & vbCrLf & strBody _

rsEmail.MoveNext

Loop
Set rsEmail = Nothing

MsgBox "Emails have been sent"
End Sub

Any ideas?
 
This should do it
Code:
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Dim strBody As String
Dim strSubject As String
Dim strContact As String

Set rsEmail = CurrentDb.OpenRecordset("QrySendEmails")

Do While Not rsEmail.EOF
    
    strEmail = rsEmail.Fields("Email").Value
    strBody = rsEmail.Fields("Body").Value
    strContact = rsEmail.Fields("ContactName").Value
    strSubject = "Subject: What Ever"
    
    DoCmd.SendObject , , , strEmail, , , _
        strSubject, "Hello " & strContact & _
        vbCrLf & vbCrLf & strBody, True

    rsEmail.MoveNext
Loop

Set rsEmail = Nothing

MsgBox "Emails have been sent"
Note: You may want to remove the true at the end of the sendobject. I needed it to do my testing.
 
Bukhix, thanks for the reply but the code is not doing anything for me. No error messages just doesn't do anything. When I take the lines to capture the Contact out then everything works fine.

Any ideas?
 
Can you strip down your db zip it up and post it here?
 

Users who are viewing this thread

Back
Top Bottom