Solved

Add attachments to email in Access

Posted on 2014-01-22
3
536 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 49

Accepted Solution

by:
Rgonzo1971 earned 350 total points
ID: 39799654
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
ID: 39799719
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
ID: 39799869
Thank you both for your time and instruction
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

777 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