Hi All,
Please assist, not sure how to email an attachment to a list of customers depending on my criteria from a query.
The list of customers will not always be the same so I can not type the email in manually into the macro emaildatabaseobject
I have the same, in a table my emails, the query determines the list.
My issue is, I dont know how to do the actual mail to the list.
Not sure which command or code to use for this.
Macro "emaildatabaseobject" will not do the job
You need to construct a concatenated string of the email addresses coming from the query. Use VBA to open a recordset based on the query and then loop through that recordset.
There will be be code samples in previous posts under Modules.
When you are building the message, you can create the .Body of the message. If you are using either Outlook or CDO, you can set up the list of recipients at the same time by stepping through a list using recordset operations. For each recipient that should get the message you will need a user@address entry which you say you already have in the table. For the message object's .To property, concatenate each desired destination with a leading semi-colon. Then when you reach the end of the recordset that will be your distro list, use the RIGHT function to take off the leading semicolon. Then send your message.
Alternative: I always used to send myself the message and assured that I was never in the list of recipients obtained from the query. So I put my own e-mail first. Then when I added the recipients, I just added the semicolon and address.
Code:
(open a recordset to the table of potential recipients)
Do Until recordset.EOF = True
IF recordset!GroupName = (desired group name) THEN
msg.To = msg.To & ";" & Trim$(recordset.UserAddress)
END IF
recordset.MoveNext
...
End While
msg.Send
Obviously I've left stuff out there, but that's the general idea. Just tack on your list of recipients until you've run out. Separate them with semicolons.
I've done that at times too. However, when I did include my own email, I'd include it in the BCC list, which would also be used for the other recipients if they were a disparate group for privacy purposes.
Actually, Cronk, I eventually did move my name from .To to .BCC because if someone did a Reply to All I would get deluged with project-oriented stuff I didn't need to keep.