I7arkHiro97
New member
- Local time
- Today, 08:19
- Joined
- Jun 29, 2010
- Messages
- 2
Hi,
I am a beginner to VBA. I am using MS access 2003. I found some code that works great for sending automatic emails to a list of recipients. My email addresses are housed in a table on access and they are pulled into a query to send an email to only those who are listed in my query.
Right now the code uses a text document as the body of the email. Is there a way to change the code in order to use a word document instead of a text document? I also want it to transfer the text and pics from the word document over to the body of email exactly how it looks. For example if the text is bold or colored, thats how I want it to look in the body of the email. However i did find code that will use a word document as the body of an email on word, I would like to do that but using VBA on access 2003.
The second thing is that I will be sending an email to a massive list of recipients. I was able to use the code to add all the email addresses to a single email on the TO: recipient from my list of email addresses from my query. Can the code be altered to show all the email addresses as Undisclosed Recipents when the email is sent? The main thing is that I want to ensure the recipients can't see the massive email list of other reciepents. Also if they click the reply to all by accident, I want them to only be able to send a reply back to just the sender.
I would really appreciate all the help. Thank you for taking the time
Here is the code I am using:
Public Function SendEMail()
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Set fso = New FileSystemObject
Subjectline$ = InputBox$("Please enter the subject line for this mailing.", _
"We Need A Subject Line!")
If Subjectline$ = "" Then
MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "E-Mail Merger"
Exit Function
End If
BodyFile$ = InputBox$("Please enter the filename of the body of the message.", _
"We Need A Body!")
If BodyFile$ = "" Then
MsgBox "No body, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain??t Got No-Body!"
Exit Function
End If
If fso.FileExists(BodyFile$) = False Then
MsgBox "The body file isn??t where you say it is. " & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain??t Got No-Body!"
Exit Function
End If
Set MyBody = fspenTextFile(BodyFile, ForReading, False, TristateUseDefault)
MyBodyText = MyBody.ReadAll
MyBody.Close
Set MyOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("MyEmailAddresses")
Set MyMail = MyOutlook.CreateItem(olMailItem)
Do Until MailList.EOF
MyMail.Recipients.Add = MailList("email")
MailList.MoveNext
Loop
MyMail.Subject = Subjectline$
MyMail.body = "Dear Recipient(s)" & "," & vbNewLine & vbNewLine & MyBodyText
MyMail.Display
Set MyMail = Nothing
Set MyOutlook = Nothing
MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing
End Function
I am a beginner to VBA. I am using MS access 2003. I found some code that works great for sending automatic emails to a list of recipients. My email addresses are housed in a table on access and they are pulled into a query to send an email to only those who are listed in my query.
Right now the code uses a text document as the body of the email. Is there a way to change the code in order to use a word document instead of a text document? I also want it to transfer the text and pics from the word document over to the body of email exactly how it looks. For example if the text is bold or colored, thats how I want it to look in the body of the email. However i did find code that will use a word document as the body of an email on word, I would like to do that but using VBA on access 2003.
The second thing is that I will be sending an email to a massive list of recipients. I was able to use the code to add all the email addresses to a single email on the TO: recipient from my list of email addresses from my query. Can the code be altered to show all the email addresses as Undisclosed Recipents when the email is sent? The main thing is that I want to ensure the recipients can't see the massive email list of other reciepents. Also if they click the reply to all by accident, I want them to only be able to send a reply back to just the sender.
I would really appreciate all the help. Thank you for taking the time
Here is the code I am using:
Public Function SendEMail()
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String
Set fso = New FileSystemObject
Subjectline$ = InputBox$("Please enter the subject line for this mailing.", _
"We Need A Subject Line!")
If Subjectline$ = "" Then
MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "E-Mail Merger"
Exit Function
End If
BodyFile$ = InputBox$("Please enter the filename of the body of the message.", _
"We Need A Body!")
If BodyFile$ = "" Then
MsgBox "No body, no message." & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain??t Got No-Body!"
Exit Function
End If
If fso.FileExists(BodyFile$) = False Then
MsgBox "The body file isn??t where you say it is. " & vbNewLine & vbNewLine & _
"Quitting...", vbCritical, "I Ain??t Got No-Body!"
Exit Function
End If
Set MyBody = fspenTextFile(BodyFile, ForReading, False, TristateUseDefault)
MyBodyText = MyBody.ReadAll
MyBody.Close
Set MyOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("MyEmailAddresses")
Set MyMail = MyOutlook.CreateItem(olMailItem)
Do Until MailList.EOF
MyMail.Recipients.Add = MailList("email")
MailList.MoveNext
Loop
MyMail.Subject = Subjectline$
MyMail.body = "Dear Recipient(s)" & "," & vbNewLine & vbNewLine & MyBodyText
MyMail.Display
Set MyMail = Nothing
Set MyOutlook = Nothing
MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing
End Function