Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36

    Add pdf file to report to email

    I have a "order receipt" report that is emailed to the customer once their order is received here.
    I want to be able to attach a pdf file (Our T&Cs- terms & conditions) to the bottom of the report.
    I have tried copying and pasting the text into the report with a text box or with an unbound object field but it keeps telling me it is too much data to put into a text box (4 pages). I have even tried to add it to the vba code but as you may already know, you can only email one pdf at a time through VBA.
    Anyone have any ideas?

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Quote Originally Posted by Cheryl R View Post
    . I have even tried to add it to the vba code but as you may already know, you can only email one pdf at a time through VBA.
    That's only with SendObject. With other methods you can have multiple attachments. One is automation:


    http://support.microsoft.com/?kbid=161088
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    Yes, I am using the SendObject method- how did you know? lol You are so smart!
    I will this and let you know how it works.

    Thank you!!!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    My ESP is strong today!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    Ok, well, that didn't work. When I click on the button, nothing at all happens.
    (yes, I followed the instructions and added the Option Explicit statement at the beginning of the module and in References added the plug-in for Outlook (though mine was 12.0, not 8.0)
    By the way, I haven't gotten to the part where I add my additional attachment, just entered the code and tried to see if it will even send anything.
    Since I have a little esp as well and know you will ask for the code, here goes:
    Private Sub EmailCustomerReport_Click(DisplayMsg As Boolean, Optional AttachmentPath)

    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment

    Contact = Me.ContactEmail

    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
    ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add(Contact) '**** Is this the proper way to enter the field from the form as being the first email to send to???
    objOutlookRecip.Type = olTo
    ' Add the CC recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("Gaddiel Lopez") '***This should only be the name in my contacts and not their email, correct?
    objOutlookRecip.Type = olCC
    ' Add the BCC recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add("Sarah White")
    objOutlookRecip.Type = olBCC
    ' Set the Subject, Body, and Importance of the message.
    .Subject = "Order ID: " & Me.OrderID & " - Customer Reference #: " & Me.ReferenceNo
    .Body = "Attached please find a complete list of the tools we received at GCTR for repair. Please review this list and make sure everything is listed correctly. If there are any discrepancies, please let us know right away. Thank you! GCTR Repair Department" & vbCrLf & vbCrLf
    .Importance = olImportanceHigh 'High importance
    ' Add attachments to the message.
    If Not IsMissing(AttachmentPath) Then
    Set objOutlookAttach = .Attachments.Add(AttachmentPath)
    End If
    ' Resolve each Recipient's name.
    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    Next
    ' Should we display the message before sending?
    If DisplayMsg Then
    .Display
    Else
    .Save
    .Send
    End If
    End With
    Set objOutlook = Nothing
    End Sub

    Thanks again for your help!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Does the code compile? With Option Explicit, this should error because the variable isn't declared:

    Contact = Me.ContactEmail

    unless it's public somewhere else. I personally always use addresses rather than contact names. That was written to be a sub that accepted arguments, so it won't work quite right as a click event. You'd have to get these some other way:

    DisplayMsg As Boolean, Optional AttachmentPath

    Is Outlook open when this runs? Is this even running (you can throw a message box in there to see)? Is the code associated with the event?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    I am testing this in the Immediate window. When I type EmailCustomerReport True, "C:\GGCTR - Master Terms and Conditions.doc", it gives me an error- Compile Error; Sub or Function not defined. So, no, it does not compile.

    I am using the Contact = Me.ContactEmail because the email this report will be sent to is entered on the form when the order is entered and yes, it is being stored in the Orders table; should I set this to that field instead of referencing a field on a form? It will never be consistently one name, it changes per order. The cc and bcc fields will be consistent. Should those be the Outlook names or email addresses?

    "DisplayMsg As Boolean, Optional AttachmentPath" - I'm confused as to what you mean by that... I copied the code from the website as instructed. I put it on the OnClick event because that is where the SendObject function works. Are you saying that I need to put this code into a Public function and just call for it on the click event?

    Yes, my Outlook is open when I try this. No, it is not even running- On the form, nothing happens when I click. In the immediate window, it throws the error as soon as I hit enter.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Using the value from the form is fine. I would probably try:

    Set objOutlookRecip = .Recipients.Add(Me.ContactEmail)

    Like I said, you can't use arguments in a click event. You can make it a function and then call it from a click event, or put it all in the click event and get the arguments a different way. It doesn't sound like the code is associated with the button:

    http://www.baldyweb.com/FirstVBA.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    Sorry, must have missed where you said I can't include arguments on a click-event. Though I am sure I am using them elsewhere in determining whether or not to save a record.
    Thanks for the link to your website and for taking the time to answer my question.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    I'd like to see it if you are doing it (using non-standard arguments). Won't be the first time I learned something new. Post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    Here is one on-click event where I use an argument (it's a standard argument so I'm not sure this will be new to you. Just saying there are instances where mine uses an argument within an On-Click event):
    Private Sub cmdSaveTool_Click()
    Me.ToolID = Me.Make & "-" & Me.Model -'this only creates the new ToolID when I add the new tool
    DoCmd.RunCommand acCmdSaveRecord -'then saves the record
    If frmName = "frmNewOrders" Then -'then looks to see if it was on the New Order/All Order screen (same screen, determined by user login)
    Forms!frmNewOrders![tblTagDetails Subform].Form.Make.Requery -'telling it to requery the form if it is New Order so it will see the new tool I just added
    End If
    DoCmd.Close acForm, Me.Name, acSaveNo -'then close the Add New Tool Form
    End Sub


    On the "Set objOutlookRecip = .Recipients.Add(Me.ContactEmail)" where does this go?
    It doesn't like it within the module where I put the function. Does that go on the on-click event?

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    I meant the arguments you had here:

    Private Sub EmailCustomerReport_Click(DisplayMsg As Boolean, Optional AttachmentPath)

    Which are not native to a click event. The recipients line was fine where it was, I was just showing a different way to get the address.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    Oh, sorry. I copied that from the microsoft link you sent me.
    As since my code was in the OnClick event, I just assumed it went there.

    When I put the code in the module rather than in the form, it does not recognize the "me..." data.

    When you say the recipient line was fine where it was, what does that mean?

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    How are you coming along? "Me" is a shortcut to refer to the object the code is in, so it never works in standard modules. You have to use full form references or pass the values in as arguments.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    Cheryl R is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    May 2013
    Posts
    36
    I have had to move on to something else momentarily, so currently they are using the SendEmail method without attaching the second file. But, some of my users are using the web-based version of Office so I suspect the SendObject method might not work this way. I have been wrong before but I will still eventually need to be able to add the second pdf file so I will have to make it work.

    So, in the Public function, what should be in parenthesis here: Set objOutlookRecip = .Recipients.Add(Contact)
    Should that be the (Forms.frmNewOrder.ContactName)?
    Or how do I pass that as an argument?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 13
    Last Post: 11-07-2012, 03:14 PM
  2. Email report as body of email (RTF)
    By TheDeceived in forum Programming
    Replies: 4
    Last Post: 07-23-2012, 06:39 AM
  3. Email report as body of email
    By chrish20202 in forum Programming
    Replies: 6
    Last Post: 01-15-2012, 07:23 PM
  4. Replies: 4
    Last Post: 04-13-2011, 10:11 AM
  5. Email from report to Email body
    By Ehmke66 in forum Programming
    Replies: 4
    Last Post: 01-03-2011, 01:06 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