473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

how do i send a word document as the body of an email in access 2003?

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 wanted to know if its possible to transfer the text and pics from the word document over to the body of the email exactly how it looks. For example if the text is bold or colored, can it tranfer over to look that way 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.

Please show me exaclty what I need to change and add, also where to put it. Like I said, I am a beginner in VBA.

I would really appreciate all the help. Thank you for taking the time

Here is the code I am using:

Expand|Select|Wrap|Line Numbers
  1. Public Function SendEMail()
  2.  
  3. Dim db As DAO.Database
  4. Dim MailList As DAO.Recordset
  5. Dim MyOutlook As Outlook.Application
  6. Dim MyMail As Outlook.MailItem
  7. Dim Subjectline As String
  8. Dim BodyFile As String
  9. Dim fso As FileSystemObject
  10. Dim MyBody As TextStream
  11. Dim MyBodyText As String
  12.  
  13. Set fso = New FileSystemObject
  14. Subjectline$ = InputBox$("Please enter the subject line for this mailing.", _
  15. "We Need A Subject Line!")
  16.  
  17. If Subjectline$ = "" Then
  18. MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
  19. "Quitting...", vbCritical, "E-Mail Merger"
  20. Exit Function
  21. End If
  22. BodyFile$ = InputBox$("Please enter the filename of the body of the message.", _
  23. "We Need A Body!")
  24. If BodyFile$ = "" Then
  25. MsgBox "No body, no message." & vbNewLine & vbNewLine & _
  26. "Quitting...", vbCritical, "I Ain??t Got No-Body!"
  27. Exit Function
  28. End If
  29.  
  30. If fso.FileExists(BodyFile$) = False Then
  31. MsgBox "The body file isn??t where you say it is. " & vbNewLine & vbNewLine & _
  32. "Quitting...", vbCritical, "I Ain??t Got No-Body!"
  33. Exit Function
  34. End If
  35. Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)
  36. MyBodyText = MyBody.ReadAll
  37.  
  38. MyBody.Close
  39. Set MyOutlook = New Outlook.Application
  40.  
  41. Set db = CurrentDb()
  42.  
  43. Set MailList = db.OpenRecordset("MyEmailAddresses")
  44.  
  45. Set MyMail = MyOutlook.CreateItem(olMailItem)
  46.  
  47. Do Until MailList.EOF
  48.  
  49. MyMail.Recipients.Add = MailList("email")
  50.  
  51. MailList.MoveNext
  52.  
  53. Loop
  54.  
  55. MyMail.Subject = Subjectline$
  56.  
  57. MyMail.body = "Dear Recipient(s)" & "," & vbNewLine & vbNewLine & MyBodyText
  58.  
  59. MyMail.Display
  60.  
  61. Set MyMail = Nothing
  62. Set MyOutlook = Nothing
  63. MailList.Close
  64. Set MailList = Nothing
  65. db.Close
  66. Set db = Nothing
  67.  
  68. End Function
Jun 29 '10 #1
2 3647
maxamis4
295 Expert 100+
This works for me in vb.net should work in access with the proper references:

Expand|Select|Wrap|Line Numbers
  1. Dim oWord As Word.Application
  2. Dim oDoc As Word.Document
  3. oWord = CreateObject("Word.Application")
  4. oWord.Visible = True
  5. oDoc = oWord.Documents.Open("c:\SomeWordFile.doc", , True)
  6. oWord.Selection.WholeStory()
  7. Dim wholeText As String = oWord.Selection.Text
  8.  
Jun 30 '10 #2
@maxamis4
Hey thanks for the info. Can you do a before and after type thing so I can see what the changes were and where into my existing code? Remember, I am a beginner at this. Thanks again for the help.
Jun 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: M. Garcia | last post by:
Good day, I created a form where one of its controls stores the hyperlink to a Word document. The form has a command button that opens the folder where the Word documents are kept using a...
4
by: neoret | last post by:
How do I send a word document as an attachement to a http call? Guess I have to parse it to bytes - does anyone know how this is done? Thanks for any help you can provide :) neoret
2
by: dawnm.jordan | last post by:
Hi, I am working on a database used to store information, and then generate customized letters. I have most of it working, (Thanks to the posts in this group =)) I have a button which can be...
1
by: yewhiong | last post by:
I have encountered an interesting problem which I hope I can find the answer here. Normally, I will enter the criteria in a field called "SerialNo" in a query called "OSY Allocation". Then I will...
5
by: mikez | last post by:
Hi, We recently built a very basic file management system for a client in Access 2003 (to use with incoming tif scans). In it we used Microsoft's Document Imaging activex viewer (from Office...
1
by: uarana | last post by:
Hi All, I've been working with Acess for a little while now but have never had to do a thing of such sort. Any help would be appreciate. Thanks Problem: A report is sent to users to fill...
2
by: rmfoley | last post by:
All, I would like to create a professional looking cover sheet with information loaded from an MS Access Report. I created the cover sheet in MS Word that includes my company logo, etc. My...
14
klarae99
by: klarae99 | last post by:
I am wondering if access 2003 has the ability to open a linked Word Document, without that document being related directly to a table (I do not need to merge data with the document). I am...
0
by: accessdumbie | last post by:
We have a small amount of information in a Word Document that I would like to print in an Access Report. We have the location of the document for each individual record stored in a hyperlink field...
4
by: acc2ess | last post by:
Hello, My problem is that I receive different Word Documents as attachments and I need to get its data into the corresponding tables in access. I have used Text Form Fields in Word...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.