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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending a Outlook Greeting Card using MS Access 2

Status
Not open for further replies.

istone

IS-IT--Management
Jan 24, 2007
139
US
Hi All,
First of all Happy Holidays.
We usually do this piece manually. I want to find out if it's possible to send a Greeting card (Outlook card) to all our clients using their email address that we have in our database. The goal will be to create a button in a form and once clicked on it'll send the same card to all the clients using their email address we have in the table.
Thank you in advance


 
A part of the answer is you can send to a number of email adresses one by one a message. How to include your greeting, maybe as an attachtment. For sending mails from access you need some vba, look eg on the name SendObject.
 
I tried the following code but I am getting this error message:
run-time error'13'
Type mismatch

and this line is highlighted "Set rs = db.OpenRecordset("SELECT Email FROM Table1")"



Private Sub Command0_Click()

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Email FROM Table1")

Do Until rs.EOF

With MailOutLook
.To = rs!Table1
.Subject = "Hey..."
.HTMLBody = "Check It Out<br><br>"
.Attachments.Add "C:\My Documents\Greetings.jpg", olByValue, , "Stuff"
.Send
End With



rs.MoveNext
Loop
End Sub
 
correction:
this line should say: .To = rs!email
 
That would be:

Dim rs As DAO.Recordset

Make sure that you have a reference to Microsoft DAO 3.x Object Library.
 
thanks

Yes I have reference to DAO3.6 Object lirary.
Now I am getting this error:
run-time error'424'
Object Required

and this line is highlighed: .To = rs!Email

Email is the name of the field where the email address is stored.

 
Remou, It did not work for me.

I have a table like this:

Client ContactName Email
ABC ABC Name ABC@yahoo.com
CDC CDC Name CDC@yahoo.com
MNB MNB Name MNB Name

I am trying to send an email and attach a card (jpg file) to the above clients using the email address in the email field.
maybe creating a button in a form and when clicked the emails are sent.

I tried the code you recommended and I could not do it.
thanks
 
Private Sub Command1_Click()
Dim email As String
Dim ref As String
Dim origin As String
Dim destination As String
Dim notes As String

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

email = Me!email


Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.To = email

End With

objOutlook.Quit
Set objEmail = Nothing

With objEmail
.To = strEmail
.Subject = "XXXX"
.Body = strBody
.Send

.Attachments.Add ("c:\My Documents\Greetings.jpg") 'add attachment
.Send
End With
 
You need to put the two examples together. The example I posted showed how to use the Outlook application and the example you have shows how to use a recordset. If something does not work, please give the error message and the line where the error occurs.

Code:
Private Sub Command0_Click()

Dim db As Database
Dim rs As Recordset
'Dont't forget to reference the Outlook Object Library
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT Email FROM Table1")

Do Until rs.EOF

With objEmail
  .To = rs!Email
  .Subject = "Hey..."
  .HTMLBody = "Check It Out<br><br>"
  .Attachments.Add "C:\My Documents\Greetings.jpg", olByValue, , "Stuff"
  '.Send
'Use Display rather than send when testing
  .Display
End With

rs.MoveNext
Loop
End Sub
 
thanks remou for your help.

The same error message: run-time error'13' Type mismatch

and this line is highlighted:
Set rs = db.OpenRecordset("SELECT Email FROM Table1")
 
Good news
I put this: Dim rs As DAO.Recordset
and now I have a message:
run-time error'-166...can't find this file. Make sure the path and file name are correct
I have to figure out why the attachment is not working.

 
The attachment is working now. The only issue is: It only send to one person, the first on the table, it doesn't loop..How do i fix that? thanks
 
I get an error message:

Run-time error'-6603....'
the item has been moved or deleted

and this line is highlighted: .To = rs!Email

and then I click end and the email is sent but to only one person the first on the table list

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top