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
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
And make sure the path is valid, do you have a subfolder named Documents in your C: drive?
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
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
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
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:
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.Code:criteria = "[Study ID]='" & [Study ID] & "'"
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
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
Likely because you were not using code tagsSo 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.
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
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.
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:
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.Code:criteria = "[Study ID]=" & Me.[Study ID]
Cheers,
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.
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
Are you using Outlook as the email client?
Yes I am using Outlook.
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