Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching a file to email 1

Status
Not open for further replies.

Eddyoftheyear

Technical User
Aug 11, 2010
57
US
Hi All,

I need help with attaching a file automatically to the email when using the send object. The document will be word or pdf.

Is there a way to automatically the file to be attached from a specific location? I am saving the file in H:/Admin/Welcome.Doc

If intResponse = vbYes Then DoCmd.SendObject , , , strEmail, , , "Test Email", , , True
 
As you know, Access only provides for the attachment of Access object like Forms, Reports, etc. I have written a little code that will open a word document, which I needed for the application I created, but I don't think that's what you want.

If you leave the object blank in the SendObject command a blank email will open. The only thing I can suggest is that there may be a way of coding Outlook to attach a specific file. To my knowledge there's no way to have Access pick an unrelated file and attach it.

Sorry.
 
I hope I did not cause confusion. I am able to do this by writing the actual e-mail in the code in the following statement, but the problem the email is moe than 255 char. it is about 15 lines.so I thought it will be easier to attach the file with the message needed to be snet.

If intResponse = vbYes Then DoCmd.SendObject , , , strEmail, , , "Test Email", "This e-mail ios to inform you about the policy change....", , True
 
O hell, I didn't understand. What I did to exceed the 255 character limit was to set part of the message in several hidden fields on either the form or report. Then the syntax is ="This is to inform you that " & [Hidden] & [Hidden2] & "Thank you."

The character limit is within the code or macro, and not what is actually posted in the mail. Hell, you could use a hidden memo field and make an email body the size of a book.
 
Of course, there is also a way to control Outlook directly from Access and you can do virtually anything that Outlook can do. I have written code to generate e-mails, select the proper mailing lists based on selected parameters, enter subject lines and text, add attachments (any document), set delivery times (i.e. time-delay the sending of the message) and even verify that the message was sent (and received.) It is a bit complex to figure everything out because the Outlook Object Model is very different from Access (or Word, or Excel) but with a bit of research it can be done. Make sure you have a Reference to the Outlook Object Library loaded. Some simple code looks like this:

Code:
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.Namespace
Dim olMessage As Outlook.MailItem

Set olNameSpace = olApp.GetNamespace("MAPI")
Set olMessage = olApp.CreateItem(olMailItem)
olMessage.Recipients.Add "jblow@dullsville.net"
olMessage.BodyFormat = olFormatHTML
olMessage.Subject = "Hey look at this!"
olMessage.Body = "I found this website while I was goofing off at work."
olMessage.Body = olMessage.Body & vbCrLf & "[URL unfurl="true"]www.CompleteWasteOfTime.org"[/URL]
olMessage.Attachments.Add "C:\ThisCoolFile.doc"
olMessage.Attachments.Add "C:\AnotherCoolFile.jpeg"
olMessage.Attachments.Add "C:\ThirdCoolFile.pdf"
olMessage.Send
Set olMessage = Nothing
Set olNameSpace = Nothing
If you want to display the message and send it yourself (after close examination) replace olMessage.Send with olMessage.Display -- naturally the code stops if it can't find "C:\ThisCoolFile.doc" and the send will fail unless there really is a jblow somewhere in dullsville. Play with it (using olMessage.Display) and see what you get... then ask more, if you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top