Link to home
Start Free TrialLog in
Avatar of Stephen Byrom
Stephen ByromFlag for Ireland

asked on

Add attachments to email in Access

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
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stephen Byrom

ASKER

Thank you both for your time and instruction