Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 38
  1. #16
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Hi Minty



    I changed the code to that shown below and now getting the following error when this Path was working previously?


    The code is now this:-
    Code:
    Private Sub cmdPDF_Click()
    
    
    10        On Error GoTo cmdPDF_Click_Error
          Dim strSQL As String
          Dim objOutlookAttach As Object
          Dim objApp As Object
          Dim objMailItem As Object
          Dim strAttachment As String
          Dim strMailItem As String
          Dim strWhere As String
          Dim strToWhom As String
          Dim strMsg As String
          Dim strSubject As String
    
    
    
    
    20    strWhere = "[CustomerID]=" & Me.CustomerID
    30    strToWhom = Me.Email
    40    strSubject = "PDF Guide"
    50    strMsg = "Find attached details of CARI Setup Process"
    60    Set objApp = CreateObject("outlook.application")
    70    Set objMailItem = objApp.CreateItem(0)
    80    With objMailItem
    90      .Subject = "CARI Setup Process"
    100     .to = Me.Email
    110     .Body = "Where's my Body"
    
    
    120   objMailItem.Attachments.Add ("C:\PDF Files\HowtoCreateCARIAccountV43.pdf")
    130   objMailItem.Display 'change to .Display if you want to just display it.
    140     End With
           
    150       On Error GoTo 0
    160       Exit Sub
    
    
    
    
    cmdPDF_Click_Error:
    
    
    
    
    170       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPDF_Click, line " & Erl & "."
    
    
    End Sub
    Attached Thumbnails Attached Thumbnails error.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  2. #17
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Put everything into variables as I suggested earlier.
    You had that before and it was working - you have now moved back to referencing it directly in the outlook settings.

    Have a workflow design and stick to it.


    1. Get your full path and filenames into variables.
    2. Check they exist.
    3. Get the rest of your outlook settings into variables.
    4. If necessary debug.print all your variables!
    5. Open the outlook object.
    6. Assign all the variables to your outlook properties.
    7. Add the attachments.
    8. Send or display the email.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #18
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Hi Vlad

    The Report I am referring to is an External PDF File stored in a Folder on my C: Drive
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  4. #19
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Hi Mike,
    I'm sorry but I thought you wanted to have two attachements to your Outlook message; one would be always the same (C:\PDF Files\HowtoCreateCARIAccountV43.pdf) and the other an Access report (rptCariProviderLetter). Now I think this report is (should) showing info for just this CustomerID by using in its criteria a refence to Me.CustomerID (you kinda refer to it but you don't use it anywhere: strWhere = "[CustomerID]=" & Me.CustomerID). So what I suggest is to edit you rptCariProviderLetter report to only return the record(s) for the current customerID loaded in your form.
    Now back to emailing,this in itself does nothing, you need to first export the report as a PDF in order to attach it
    Code:
    30    strDocName1 = "rptCariProviderLetter"
    This is how I would try to do it (if my assumtions are correct):
    Code:
    Private Sub cmdPDF_Click()
    
    
    
    
    On Error GoTo cmdPDF_Click_Error
          Dim strSQL As String
          Dim objOutlookAttach As Object
          Dim objApp As Object
          Dim objMailItem As Object
          Dim strAttachment As String
          Dim strMailItem As String
          Dim strWhere As String
          Dim strToWhom As String
          Dim strMsg As String
          Dim strSubject As String
    
    
    strWhere = "[CustomerID]=" & Me.CustomerID
    strToWhom = Me.Email
    strSubject = "PDF Guide"
    strMsg = "Find attached details of CARI Setup Process"
    
    
    Set objApp = CreateObject("outlook.application")
       
    Set objMailItem = objApp.CreateItem(0)
    
    
    objMailItem.Subject=strSubject
    objMailItem.To=strToWhom
    objMailItem.Body=strMsg
    
    objMailItem.Attachments.Add ("C:\PDF Files\HowtoCreateCARIAccountV43.pdf")
    'now lets attach the report
    'we need to export it first
    strAttachment ="C:\PDF Files\CariProviderLetter_ID" & me.CustomerID & ".pdf"
    Docmd.OutputTo acOutputReport, "rptCariProviderLetter", acFormatPDF, strAttachment
    'if your report is set to show all customers but you want to send the info just for the current customer comment out the line above and un-comment the three lines below
    'Docmd.OpenReport "rptCariProviderLetter", acViewPreview,, strWhere , acHidden
    'Docmd.OutputTo acOutputReport, "rptCariProviderLetter", acFormatPDF, strAttachment
    'DoCmd.Close acReport, "rptCariProviderLetter", acSaveNo
    objMailItem.Attachments.Add strAttachment)
    
    
    objMailItem.Display 'change to .Display if you want to just display it.
           
    On Error GoTo 0
    Exit Sub
    
    
    
    
    cmdPDF_Click_Error:
    
    
    
    
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPDF_Click, line " & Erl & "."
    
    
    
    
    End Sub
    Cheers,
    Vlad
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #20
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Hi Vlad
    Many thanks for looking at this for me.

    The attachments I need are as follows:-
    "C:\PDF Files\CreateCARIAccount.pdf" - This is the external PDF file
    "rptCariProviderLetter"- which is a normal Access Report

    When I try to run the code I get the following Error:-

    The Code is:-



    The current Code is:-

    Code:
    Private Sub cmdPDFEMail_Click()
    
    
        On Error GoTo cmdPDFEMail_Click_Error
    Dim strSQL As String
          Dim objOutlookAttach As Object
          Dim objApp As Object
          Dim objMailItem As Object
          Dim strAttachment As String
          Dim strMailItem As String
          Dim strWhere As String
          Dim strToWhom As String
          Dim strMsg As String
          Dim strSubject As String
    
    
    
    
    strWhere = "[CustomerID]=" & Me.CustomerID
    strToWhom = Me.Email
    strSubject = "PDF Guide"
    strMsg = "Find attached details of CARI Setup Process"
    
    
    
    
    Set objApp = CreateObject("outlook.application")
       
    Set objMailItem = objApp.CreateItem(0)
    
    
    
    
    objMailItem.Subject = strSubject
    objMailItem.To = strToWhom
    objMailItem.Body = strMsg
    
    
    objMailItem.Attachments.Add ("C:\PDF\CreateCARIAccount.pdf")
    'now lets attach the report
    'we need to export it first
    'strAttachment = "C:\PDF\CreateCARIAccount" & Me.CustomerID & ".pdf"
    'DoCmd.OutputTo acOutputReport, "rptCariProviderLetter", acFormatPDF, strAttachment
    'if your report is set to show all customers but you want to send the info just for the current customer comment out the line above and un-comment the three lines below
    DoCmd.OpenReport "rptCariProviderLetter", acViewPreview, , strWhere, acHidden
    DoCmd.OutputTo acOutputReport, "rptCariProviderLetter", acFormatPDF, strAttachment
    DoCmd.Close acReport, "rptCariProviderLetter", acSaveNo
    objMailItem.Attachments.Add strAttachment
    
    
    
    
    objMailItem.Display 'change to .Display if you want to just display it.
        
        On Error GoTo 0
        Exit Sub
    
    
    cmdPDFEMail_Click_Error:
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPDFEMail_Click, line " & Erl & "."
    
    
    End Sub
    Attached Thumbnails Attached Thumbnails error.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  6. #21
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    This is getting to be like a game of 'Whack a Mole'?

    AT first the file is "C:\How to Create CARI-Account V4.3" then
    "C:\PDF\CreateCARIAccount.pdf" then
    "C:\PDF Files\HowtoCreateCARIAccountV43.pdf" then
    "C:\HowtoCreateCARIAccountV43.pdf" then
    "C:\PDF Files\HowtoCreateCARIAccountV43.pdf" then

    and now in Post 20 you say the file is "C:\PDF Files\CreateCARIAccount.pdf" yet you have "C:\PDF\CreateCARIAccount.pdf" in the code????

    21 posts in this forum and 37 in UA?

  7. #22
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Hi Welshgasman

    Too true. The file is definitely CreateCARIAccount.pdf now.

    I am intrigued by the name, are you an actual Gasman from Wales?

    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  8. #23
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    I live in Wales. My user name comes from the time I served in the Merchant Navy on LPG Gas ships. We were generically called Gasmen within the company as we tended to serve predominantly on those ships.

    Choose a name for the file and stick with it.
    Choose a location for the file and stick with that also.
    Then put that EXACT location and file name in the code, either hard coded or as a variable. If you choose a variable, make sure that is the correct variable you choose to add as the attachment.

  9. #24
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    I used to live in Wales, Risca. Joined the Army in 1962 - served for 33 years.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  10. #25
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    It does not get said much over here, but "Thank You for your service".

  11. #26
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Hi Mike,

    Again you are mixing methods and chucking the various parts of solutions presented into a mixing bowl and coming up with an Eton Mess...
    Try this;
    Code:
    Private Sub cmdPDFEMail_Click()
    
    
        On Error GoTo cmdPDFEMail_Click_Error
        Dim strSQL As String
        Dim objOutlookAttach As Object
        Dim objApp As Object
        Dim objMailItem As Object
        Dim strAttachmentPDF As String
        Dim strAttachmentREP  As String
        Dim strMailItem As String
        Dim strWhere As String
        Dim strToWhom As String
        Dim strMsg As String
        Dim strSubject As String
        '
        '   ======================= Set up all your variables =========================
        strWhere = "[CustomerID]=" & Me.CustomerID
        strToWhom = Me.Email
        strSubject = "PDF Guide"
        strMsg = "Find attached details of CARI Setup Process"
        
        'Set your PDF path here
        strAttachmentPDF = "C:\PDF\CreateCARIAccount.pdf"
        'Set the report path here
        strAttachmentREP = Application.CurrentProject.Path & "\rptCariProviderLetter_" & Me.CustomerID & ".pdf"
        
        '   ========================= 'create the report ==============================
    
    
        DoCmd.OpenReport "rptCariProviderLetter", acViewPreview, , strWhere, acHidden
        DoCmd.OutputTo acOutputReport, "rptCariProviderLetter", acFormatPDF, strAttachmentREP
        DoCmd.Close acReport, "rptCariProviderLetter", acSaveNo
        '
        '   ========================= Now do some outlook stuff ! ===================
        
        Set objApp = CreateObject("outlook.application")
        Set objMailItem = objApp.CreateItem(0)
        objMailItem.Subject = strSubject
        objMailItem.To = strToWhom
        objMailItem.Body = strMsg
        'add the pdf
        objMailItem.Attachments.Add strAttachmentPDF
        'now lets attach the report
        objMailItem.Attachments.Add strAttachmentREP
        
        objMailItem.Display 'change to .Send if you want to just send it.
        
        On Error GoTo 0
        Exit Sub
    
    
    
    
    cmdPDFEMail_Click_Error:
    
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPDFEMail_Click, line " & Erl & "."
    
    
    
    
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  12. #27
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Hi Minty

    Now the Code & Explanations was very easy to follow.

    Now when I run the Code I get the attached error.

    When I hit Debug it highlights the following Line:-

    objMailItem.Attachments.Add strAttachmentPDF

    The path is correct as I have checked it numerous times.
    Attached Thumbnails Attached Thumbnails error.JPG   pdf.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  13. #28
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Okay let prove it's not just an outlook thing.

    Add the following code before the creating the report section

    Application.FollowHyperlink strAttachmentPDF
    Exit Sub

    It should open the pdf file.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  14. #29
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Can you please try to wrap the path in parenthesis:

    objMailItem.Attachments.Add (strAttachmentPDF)

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  15. #30
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,557
    Now get the following error:-
    Attached Thumbnails Attached Thumbnails error.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-19-2017, 02:31 PM
  2. Replies: 5
    Last Post: 04-27-2015, 12:26 PM
  3. Replies: 5
    Last Post: 09-05-2014, 12:06 PM
  4. Attach Report to Email
    By teebumble in forum Reports
    Replies: 5
    Last Post: 11-28-2012, 05:42 PM
  5. Replies: 2
    Last Post: 12-28-2011, 09:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums