Add Date To title when using PrintToPDF?

Is there a way to append “Today’s Date” to a title when using PrintToPDF? My procedure analyzes 37 fields in my database, printtopdf using a data tile, the file is saved to a folder, then opens the pdf to view. The procedure gives the pdf a name using the let statement, but would I like it to show the date printed - example: “SumRpt 08/22/18” Here’s the end of my procedure - Thank you:

Let thesumrpt =“SumRpt”
OpenForm “SummarizedAnalysisReport”
printtopdf dbsubfolder(" PDFs RetentionSchedule")+"/"+(“5 RRSRecertSummary”)+"/"+ thesumrpt+".pdf", “orientation”,“portriat”,“onerecord”,“true”
openanything dbsubfolder(" PDFs RetentionSchedule")+"/"+(“5 RRSRecertSummary”)+"/"+ thesumrpt+".pdf"

If by “title” you mean “filename” then sure, just set it up when you define the file name. Conveniently you were already setting this up in a variable in the first line of your code.

Let thesumrpt ="SumRpt "+datepattern(today(),"MM/DD/YY")
OpenForm "SummarizedAnalysisReport"
printtopdf dbsubfolder(" PDFs RetentionSchedule")+"/"+("5 RRSRecertSummary")+"/"+ thesumrpt+".pdf",     "orientation","portriat","onerecord","true"
openanything dbsubfolder(" PDFs RetentionSchedule")+"/"+("5 RRSRecertSummary")+"/"+ thesumrpt+".pdf"

If you mean you want this to print in the report itself, you would do that with a Text Display object on the header tile in the SummarizedAnalysisRport form.

Thanks Jim, right… I meant “File Name”. I already have the date printed on the report itself. But, when I use the +datepattern(today(),"MM/DD/YY as shown above, the procedure doesn’t complete, I get the following message: “PrintToPDF failed because “/Users/dnorwood/Desktop/PanX Development/ PDFs RetentionSchedule/5 RRSRecertSummary/SumRpt 08/22/18.pdf” is not a valid path.” If I eliminate the date it works fine. We might run a report today, and another a month from now - that’s why I was wanting to add the date to the file name.

The slashes in your date are being interpreted as indicators of new folder names. Try periods or spaces.

Ahhh, thanks for the explanation Michael, that works - :grinning:

One other note: it is not necessary to open the form. You just include the formname as one of the options when using printtopdf. It works faster when you don’t open the form.

This option does not work for me in a quick test.

My procedure first calls the data sheet and does some selections there. Then it opens a form and prints that form to PDF.

When I (instead of opening the form) use the “Form” option with the printtopdf statement, it fails to print the form and prints the data sheet.

I just tried this again. I found that if there are no forms open, and only the datasheet, then printtopdf will not print a form, but, as you noticed, only the datasheet. I had never tried that situation before.

That is a known bug. You need to open a form, any form, and then use printtopdf.

In my case 2 other forms and the data sheet were open, but the printtopdf “form” option did not work; the statement printed the data sheet.

Your syntax may be at fault. Things need to be in the manner that is used in the examples in Help. Post what your statement is and we can look for what is wrong.

I can confirm what Kurt has said. Another test showed that the datasheet will print in response to a printtopdf statement even when another form is open. So I think the only successful way to use printtopdf with the “form” option is be have the Datasheet closed.

And I do it all the time with the data sheet open. This works:

Openform "Account"
printtopdf "","Printer","","Form","Account","Height",11,"Width",8.5,"orientation","portrait"
printtopdf "","Printer","","Form","Envelope","Height",9.5,"Width",4.125,"orientation","landscape"


Post your code.

Bruce, you are right. As the documentation clearly says:

printtopdf “Invoices.pdf”,“Form”,“Invoice Template”
Note: This option will only work if the current window is a form window. If the current window is a data sheet or procedure window, that window will be printed even if an alternate form has been specified.

In my tests, the other form was open, but it was not the active window.