angie said:
i have been searching the internet for two days now and i am really
confused with what i have to do. i have a table with all my clients' email
addresses. my goal is to send separate email with pdf attachment to each
customer separately (not like bcc).
i assume i have to create a form with message subject, message body, etc.
then i need a "sendemailtoall" command button.
could someone help me? i need the code i have to paste in a module.
i am using office 2003.
What have you got so far? Basically you need to combine two separate
concepts. Sending an Email that includes data from a Form for some of its
components and looping through a set of records pulled from a table.
Concept 1)
Assuming your PDF attachment is being created with Access 2007's built in
PDF capability the simplest method is to use the SendObject method of the
DoCmd object...
DoCmd.SendObject acSendReport,"ReportName", acFormatPDF,
"(e-mail address removed)",,,"Some Subject","Some Message",True
I'm guessing about the acFormatPDF as I don't actually know what the pdf
constant is for Access 2007 having never used it.
Now, If that function were being called in a Form's code module, it is
relatively easy to replace argument literals with references to controls on
the form...
DoCmd.SendObject acSendReport,"ReportName", acFormatPDF,
"(e-mail address removed)",,,Me.Subject,Me.MessageBody,True
In the above the subject and message body are being pulled from the form.
Concept 2)
Retrieve the Emails from your table and loop through the results sending an
Email in each loop cycle. I personally would use a DAO Recordset for
this...
Dim rs as DAO.Recordset
Dim db as Database
Dim sql as String
Set db = CurrentDB
sql = "SELECT EmailAddress FROM SomeTable"
Set rs = db.OpenRecordset(sql,dbOpenSnapshot)
Do Until rs.EOF
DoCmd.SendObject acSendReport,"ReportName", acFormatPDF,
rs!EmailAddress,,,Me.Subject,Me.MessageBody,True
rs.MoveNext
Loop
Notice how inside the loop a reference to the EmailAddress field within the
Recordset has been substituted for a hard-coded literal.
Note that I included a final "True" argument in all of the SendObject calls
above. That would be there for testing as it causes the message to be
displayed on-screen before sending (at which point you can cancel sending
it). Once you have the routine doing what you want, changing that to False
would cause the message to be sent automatically in the background.