473,757 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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 3667
maxamis4
295 Recognized Expert Contributor
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
I7arkHiro97
2 New Member
@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
1709
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 RunMacro command. What I want to do is to get the path to the document and stored it in the control as a hyperlink.
4
1534
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
2151
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 clicked and it opens word and fills in the blanks of my template appropriately, with the exception of 2 areas. These areas of the letter need to be pulled from subforms of the existing form, and in the word document they need to be a list or...
1
2163
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 print the word document that is mailmerged with that query "OSY Allocation". I hope to make the above steps more simple by designing a form with a textbox to enter the "SerialNo" and a button to print, which will open up the word document. Any...
5
6107
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 2003). The viewer seems to be a bit 'buggy', in that sometimes if you preview a tif image using the activex on a form, then goto another form, and then come back to preview the same image again on the first form, the preview no longer shows up...
1
1883
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 out. The users fill out the text fields in the Word document and send it back. Now i need to develop a code such that it opens that Wird Document, taken all the fields and places them in thier proper headings within an Access Table. I'm stilll...
2
4186
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 only problem is when I insert the Word doc, the sizing is different. (i.e. the word document's width is 7.5", but when I insert it into the Access report - it's about 5")
14
8688
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 working on an inventory control database, and would like to create a 'Users Manual' to outline how we prepare items to be inventoried, how to use the database and general information about giftshop activities. We already have an Office Manual in Microsoft...
0
1203
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 in that record. The report is the pertinent data for that record. We are currently pasting the information in the word document into a memo field but it does not format correctly. We cannot control the formatting of this data because we get it...
4
2197
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 Document and could save it in text format and imported it in ms access, but this way takes long time.
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9884
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.