473,399 Members | 3,888 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.

Insert Email Attachment using VBA

93
I have an event that creates and email that works perfect however, now I want the code to find a file on our server and insert it as an attachment. I really want to use a pdf version but here is an example of the code calling for a Word document.

The code to call the document is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. stDocName = "S:\Misc\Policy\What to have prepared for audit.doc"
  3.  
  4.  
My Send obect code is a follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.SendObject acDocument, stDocName, acFormatRTF, , , , _
  3.  
  4.  
I get an error message that states "The Microsoft.Jet database engine could not find the object 'S:\Misc\Policy\What to have prepared for audit.doc'. Make sure the object exists and that you spell its name and the path name correctly.

Please note the document is located in a different folder on the same network drive that the database resides. I tried to move the document to the same folder as the database and redirect it to that folder but it still did not work.

Any suggestions?
Nov 6 '08 #1
2 14231
PianoMan64
374 Expert 256MB
I have an event that creates and email that works perfect however, now I want the code to find a file on our server and insert it as an attachment. I really want to use a pdf version but here is an example of the code calling for a Word document.

The code to call the document is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. stDocName = "S:\Misc\Policy\What to have prepared for audit.doc"
  3.  
  4.  
My Send obect code is a follows:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.SendObject acDocument, stDocName, acFormatRTF, , , , _
  3.  
  4.  
I get an error message that states "The Microsoft.Jet database engine could not find the object 'S:\Misc\Policy\What to have prepared for audit.doc'. Make sure the object exists and that you spell its name and the path name correctly.

Please note the document is located in a different folder on the same network drive that the database resides. I tried to move the document to the same folder as the database and redirect it to that folder but it still did not work.

Any suggestions?

Hey clloyd,

Unforturenetly, SendObject does not support attachments unless, it is a Table, Query, Form, Report, or Code Module to be sent. other than that, it will not support creating an attachment to an email.

If you're wanting to send an email, and say you have outlook installed on your machine, then you can use the following example to send an email. It is a little more involved, but it does support sending any kind of file you want to attach to an email.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ObjOutlook as Outlook.Application
  3. Dim ObjOutlookMsg as Outlook.MailItem
  4. Dim objOutlookRecip as Outlook.Recipient
  5. Dim objOutlookAttach as Outlook.Attachment
  6.  
  7. Set ObjOutlook = New Outlook.Application
  8. Set objOutlookMsg = ObjOutlook.CreateItem(olMailItem)
  9.  
  10. With objOutlookMsg
  11.  
  12.      Set ObjOutlookRecip = .Recipients.Add("Name Of Person or Email Address here")
  13.      'repeat previous steps for as many users that you're going to send the email too.
  14.      objOutlookRecip.Type = olTo
  15.      .subject = "Type the subject that you want here"
  16.      Set objectlookAttach = .Attachments.Add("Full Path of File and File Name")
  17.  
  18.      For Each objOutlookRecip in .Recipients
  19.           If Not objOutlookRecip.Resolve Then
  20.                objOutlookMsg.Display
  21.           End if
  22.      Next
  23.      .Send
  24. End with
  25.  
Nov 10 '08 #2
clloyd
93
Thank you for the information. I will see what I can do with this or I may just turn the documents into a report and attach them that way.
Nov 10 '08 #3

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

Similar topics

3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
7
by: Susan Bricker | last post by:
I would like to generate a report (I have the report working already) using MS/ACCESS 2000 and then have the ability to send the report as an email attachment to my colleagues. I have looked...
3
by: Prakash Wadhwani | last post by:
Hi !! I have been browsing around but have not been able to find a simple, lucid solution ... or maybe I'm just too confused. I know this has been asked before by many ... but pls bear with me. ...
1
by: Sniper | last post by:
Hi guys I am retrieving an attachment using a web service. what would be the fastest way to download the attcahment ? WSE Attacahment or byte array or any other methods ??? tahnks in...
2
by: Bijesh | last post by:
Hi All, Is it possible to get notified on CD/DVD insert/remove notifications using FileSystem hooks? Is there any better way to get these notifications? Thanks in advance, Bijesh
6
by: c_shah | last post by:
how to save outlook email attachments using VB.net?
6
by: brendan_gallagher_2001 | last post by:
Hi, Does anyone know how to create an attachment using a stream in classic ASP. I can see that it can be done in ASP.Net as per the article below: Initializes a new instance of the Attachment...
5
by: xmaverick | last post by:
Hello, I'm a newbie to perl and i'd like some assistance trying to figure out how to send an attachment using MIME::Lite. I have searched the net far and wide and have used and modify different...
0
by: peterschedler | last post by:
How do I send an MS Word (2002) document file ( 140 MB )as a .txt email attachment and how can the recipient open it ? I am using ORANGE webmail and Mozilla Firefox .
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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
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.