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
Solved

Add attachments to email in Access

Posted on 2014-01-22
3
538 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 50

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

856 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