Solved

Add attachments to email in Access

Posted on 2014-01-22
3
526 Views
Last Modified: 2014-01-22
Hi,
I have some code from Ron De Bruin which I am trying to get to work with adding attachments. It breaks down at line 31 with the error "Type mismatch" yet I have declared the strings early on. see attached code;
Option Compare Database
Option Explicit

Public Sub EmailProdRprt()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim ProdRprt1 As String
    Dim ProdRprt2 As String
    ProdRprt1 = "H:\All\Temp\ProdRprt.pdf"
    ProdRprt2 = "H:\All\Temp\ProdRprt.xlsx"

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    Dim strMsg As String
    Dim strTo As String
    Dim strCopyTo As String
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strTo = "someone@somewhere.com;someoneelse@somewhereelse.com"
    strMsg = "Testing" 'Forms!frmShiftWarning.txtMsg
    strCopyTo = "copiedto@somewhere.com" 'Forms!frmShiftWarning.txtCopyTo
    With OutMail
        .To = strTo
        .cc = strCopyTo
        .BCC = ""
        .Subject = "Production Reports"
        .Body = strMsg
        .Attachments.Add ProdRprt1, ProdRprt2
        .Display
'        .Send
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

Open in new window


As usual, any help is greatly appreciated.
Thanks
0
Comment
Question by:Stephen Byrom
3 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 350 total points
Comment Utility
Hi,

You can only add one at a time

.Attachments.Add ProdRprt1
.Attachments.Add ProdRprt2

Open in new window

Regards
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 150 total points
Comment Utility
In addition to what Rgonzo1971 said, the *reason* you are getting a type mismatch error is that the second parameter in the Attachment.Add method is attachment "Type", which is defined as a Long Integer.

The syntax for the add function contains several optional parameters - properties of the attachment.  See this KB topic for details:

http://msdn.microsoft.com/en-us/library/office/ff869553.aspx
0
 
LVL 1

Author Closing Comment

by:Stephen Byrom
Comment Utility
Thank you both for your time and instruction
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now