Solved

Add attachments to email in Access

Posted on 2014-01-22
3
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 51

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

739 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