I have been working on an address book of customer details and contact information with the option to email one contact or a list of selected contacts (via check box to be included and a make table query that populates the BCC field), these contacts have been seperated into catagories of wholesale, retail, suppliers...etc. The email code I have used is not mine, though I have tweaked it to suit my needs.
I have been looking for the code to on the forum to make the body of the email include a generic html file for the users of the DB stored in a specific folder on the c: of each users computer. Pasted Below is the code I have used to generate the email and populate the BCC field.
I know how to send the html file as an attachment, but that is not what I have been looking for.
If anyone can help it would be greatly appreciated. Also If you would like to see how it works let me know.
Thanks in advance,
Kevin.
I have been looking for the code to on the forum to make the body of the email include a generic html file for the users of the DB stored in a specific folder on the c: of each users computer. Pasted Below is the code I have used to generate the email and populate the BCC field.
I know how to send the html file as an attachment, but that is not what I have been looking for.
Code:
Private Sub cmdSendEmailToAll_Click()
'Use this code in the build event part of a command button
'to send EMail to everyone in a table having an EMail address.
'This saves you the time and trouble of using contacts in Outlook.
'The first problem I encountered was configuring access to 'talk to' Outlook.
'A helpful person told me to try the following, which I did, and it worked!!
'Open a code window and make sure the following are checked (Tools--->References)
'They are not all checked by default, so you will have to do it.
'Visual Basic for Applications
'Microsoft Access 9.0 Object Library
'OLE automation
'Microsoft ActiveX Data Objects 2.1 Library
'Microsoft DAO 3.6 Object Library
'Change table names and field names in this code to fit your table structure
'Every record in the table you reference must contain an EMail address field.
'In this code, I use a field called EMailAddr.
'Open Outlook and make sure the bcc field is displayed before trying to use the program.
'After opening Outlook, minimize it. The code will run a lot quicker if you don't have to wait for outlook to open.
'If all records in your table do not contain an EMail Address, then
'you should run a MakeTable query first and create a new table.
'I use one field table, with EMailAddr as the field name
'The only records are those having an EMail Address
'Reference the new table in this code.
'The table will be deleted and recreated each time you send an EMail.
'If you do not have to run the MakeTable query (because everyone in your main table has an EMail address)
'comment out the next three lines:
Dim strDocName As String
strDocName = "tblEmailIncluded"
DoCmd.OpenQuery "qryEmailIncluded"
On Error GoTo ErrHandle
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strAddress As String 'this creates the Email addresses
Dim strTo As String 'this is needed to populate the TO in the EMail
Dim strCC As String 'this is needed to populate the CC in the EMail
Dim strBCC As String 'this is needed to populate the BCC in the EMail
Dim strSubject As String 'this is needed to populate the SUBJ in the EMail
Dim strBody As String 'this is needed to populate a portion of the message text in the EMail
'The following code opens up a record set based on the table called tblVolunteers, which is my main table.
'Replace "tblVolunteers" with the name of the table containing the EMail Addresses. Be sure to include the quotes.
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblEmailIncluded", dbOpenSnapshot)
'I don't know if the following code works, as I never tested it.
If rst.BOF = True And rst.EOF = True Then
MsgBox "There must be an error in the query as there are no EMail Addresses listed!"
GoTo ErrExit
End If
With rst
.MoveFirst 'go to the first record
strAddress = .Fields("EmailAddress").Value
'replace EmailAddress with the name of your EMail field. Be sure to use the quotes
strBCC = strAddress
.MoveNext 'get all subsequent addresses and separate each with a semi-colon
Do While .EOF = False
strAddress = .Fields("EmailAddress").Value
'*** Replace "EMailAddress" with the name of your field
strBCC = strBCC & "; " & strAddress
.MoveNext
Loop
End With
strTo = ""
'replace with your own EMail address. It will go into the TO field
'Note: I put all addresses in the BCC field and mail it to myself as
'this will protect the privacy of other peoples mail addresses
'Each person will receive an EMail, without knowing who else got it
'This is done for security reasons
strCC = ""
'The CC field will be left blank, unless you put something between the quotes
strBCC = strBCC
'All the EMail address, with a semi-colon separating them
strSubj = ""
'This will input a generic subject for your EMail. If you don't
'want a generic subject, just use the quotes, with nothing between them
strBody = ""
'Chr$(13) will insert a blank line in the subject of your EMail
'Anything between the quotes will be inserted. You can edit, as required before sending
'If you want the subject to be blank, just put the quotes, with nothing between them
DoCmd.SendObject , , , strTo, , strBCC, strSubj, , True
'Note the above order. This code fills in the TO, BCC, Subj, and Text blocks of the EMail form
ErrExit:
Exit Sub
ErrHandle:
MsgBox Err.Description
Resume ErrExit
Resume
End Sub
If anyone can help it would be greatly appreciated. Also If you would like to see how it works let me know.
Thanks in advance,
Kevin.
Last edited: