Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32
  1. #16
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Your path reverted to be missing the back slash so the file name will be "C:\Documents\InvoicesForApprovalSECIM08-78.pdf", is that what you want?


    Can you please try it with the back-slash?
    DoCmd.OutputTo acOutputReport, "", acFormatPDF, fileName
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  2. #17
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    And make sure the path is valid, do you have a subfolder named Documents in your C: drive?
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #18
    snsmith is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    23
    Oh my gosh, what facepalm moment that was! I didn't have the full folder path: This worked almost perfectly! The invoice is generated, renamed and placed into the appropriate folder BUT it's not refreshing the data on the form that I have. This is supposed to be filtered with "[Study ID]=" & [Study ID]

    Updated Code: I hope this is helpful. I'm just trying to help so you don't have to go back and look at other posts.
    Dim reportName As String
    Dim fileName As String
    Dim criteria As String




    reportName = "Invoice"
    fileName = "c:\Users\Snsmith\Desktop\InvoicesForApproval" & [Invoice #].Value & ".pdf"
    criteria = "[Study ID]=" & [Study ID]


    DoCmd.OpenReport reportName, acViewPreview, criteria, acHidden
    DoCmd.OutputTo acOutputReport, "", acFormatPDF, fileName
    DoCmd.Close acReport, reportName, acSaveNo

  4. #19
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    You still do not have the trailing backslash for the path?????

    Post what you are actually using, within code tags would be appreciated as well? Use the # icon
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #20
    snsmith is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    23
    So odd as I do have the backslash on my code. Not sure why it's not on the paste side of the code. I'll try again.

    Code:
    Dim reportName As StringDim fileName As String
    Dim criteria As String
    
    
    
    
    reportName = "Invoice"
    fileName = "c:\Users\Snsmith\Desktop\InvoicesForApproval\" & [Invoice #].Value & ".pdf"
    criteria = "[Study ID]=" & [Study ID]
    
    
    DoCmd.OpenReport reportName, acViewPreview, criteria, acHidden
    DoCmd.OutputTo acOutputReport, "", acFormatPDF, fileName
    DoCmd.Close acReport, reportName, acSaveNo

  6. #21
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    So what exactly is happening? You get a PDF invoice not matching the [Study ID]? I haven't asked before, just assumed it is a number, but if it is text it should be wrapped in single quotes:
    Code:
    criteria = "[Study ID]='" & [Study ID] & "'"
    Maybe you could prepare a small db sample with just the required objects (tables, form, report) with just a few "dummy records to illustrate the issue.

    You could also look at this thread in another forum for an alternate way of doing what you originally posted (emailing individual reports):
    https://www.access-programmers.co.uk.../#post-1764086

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

  7. #22
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Added in error
    Last edited by Welshgasman; 09-09-2021 at 03:02 AM. Reason: getting mixed up with Invoice and Study fields
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #23
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    So odd as I do have the backslash on my code. Not sure why it's not on the paste side of the code. I'll try again.
    Likely because you were not using code tags

    Another good reason to use them, as the site strips out some characters if not.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #24
    snsmith is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    23
    The Study ID is an autogenerated number. When I do the PDF the file name is as it should be and in the right location, but when I open it the invoice # is a different invoice# and the data within the pdf includes everything on that particular report with no filters. I'm trying to do a mini db of the issue but it's taking some time.

  10. #25
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    You should check the Where condition:
    - Is the [Study ID] field included in the Invoice report record source (table\query)?
    - Is the text box bound to [Study ID] on your form called "Study ID"?
    If you would use Me. then the VBA Intellisense would kick in and help you choose the right control:
    Code:
    criteria = "[Study ID]=" & Me.[Study ID]
    TO check if you get the right invoice right away change remove the acHidden from the OpenReport line and put a break on the Docmd.OutputTo one; when the code stops you should be able to inspect the report to see if you have the right one.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #26
    snsmith is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    23
    That did help as I was able to see that I had a space in the name so needed to add the underscore. I've done a very scaled down version of what I have so you can see what's happening.

    The "Generate Invoice Emails" works perfectly on my side, but issue with the test db. Ideally, I'd love to have that button generate the email, create the invoice, save the invoice then attach the same invoice to the email. I'm hoping that if I can at least get it to cycle through to save the invoices then I can consolidate into the code to generate the emails.
    Attached Files Attached Files

  12. #27
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Break it down into steps.
    I would
    Create and Save an Invoice, Then create an email and then attach it to an email.
    3 steps there to work on.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #28
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Are you using Outlook as the email client?
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #29
    snsmith is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2019
    Posts
    23
    Yes I am using Outlook.

  15. #30
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    Please have a look at the attached file, clicking the first button should do what you want (I had to change some field names in the recordset to match the query fields and removed the amount as it was not in the query, you should be able to edit it to match your actual db).

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

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

Similar Threads

  1. Saving Email Attachments To Folder
    By DMT Dave in forum Access
    Replies: 18
    Last Post: 06-01-2021, 02:40 PM
  2. Email with Bcc only. No attachments
    By shuddle in forum Forms
    Replies: 42
    Last Post: 02-05-2021, 11:02 AM
  3. Replies: 2
    Last Post: 08-08-2019, 11:03 AM
  4. Replies: 4
    Last Post: 03-11-2015, 12:01 PM
  5. Replies: 2
    Last Post: 01-29-2014, 03:19 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