Changing report name on the fly

  • Thread starter Thread starter Greg Casper
  • Start date Start date
G

Greg Casper

I have a report which is called by a button on a form. This report, rather
than printing, creates a PDF file by specifying a specific printer in the
page setup for the report and using Acrobat PDFWriter as the printer. I want
to be able to change the name of the report dynamically, rather than each
instance saving as the report name. How can I do this?

Thanks

Greg
 
Greg Casper said:
I have a report which is called by a button on a form. This report,
rather than printing, creates a PDF file by specifying a specific
printer in the page setup for the report and using Acrobat PDFWriter
as the printer. I want to be able to change the name of the report
dynamically, rather than each instance saving as the report name. How
can I do this?

I could be wrong, but I don't think it's possible to change the *name*
of a report as you print it. You could change its Caption property, if
that should happen to be what the print driver is looking at. I don't
suppose the PDFWriter provides a means to specify the output file name
on the fly? I'd think that would be a good feature to have.

I can only think of two methods to work around this problem, if there's
no way to override the operation of the print driver.

1. Print the report to create the file, and then, as soon as the file
has been created, rename it in code using the Name statement. There may
or may not be a trick to identifying when the PDFWriter is done with the
file so that you can rename it.

2. Change the name of the report object, using DoCmd.Rename or some such
method, immediately before printing it. <Shudder!> This is a lousy
alternative. Even making a copy of the report object with the name you
want, and then printing that, is a very bad option.

Of these two alternatives, I'd certainly go with the first, given a
choice. But best would be to find a way to tell the PDFWriter what name
to use.
 
There have been several mentions here of freeware and inexpensive shareware
to create PDF files. Some searching at http://groups.google.com might pay
off with a lead to a package that you can control as you need.

Larry Linson
Microsoft Access MVP
 
For W95, 98 the pdfwriter stores the file name in the Win.ini file.

You can set it using the following code.

Declare Function aht_apiWriteProfileString Lib "kernel32" Alias
"WriteProfileStringA" (ByVal strAppName As String, ByVal strKeyName As
String, ByVal strValue As String) As Integer

Public Sub ChangePdfFileName(strFile As String)
Call aht_apiWriteProfileString("Acrobat PDFWriter", "PDFFileName",
strFile)
End Sub

for WNT, 2K, XP it is stored in the registry.

download RegSettings.zip from http://www.mvps.org/vb/index2.html?samples.htm
add the class cRegSettings to your project. I think you may need to tweak
some of the constant definitions a bit for Access.

Dim objReg As cRegSettings
Dim strFile as String
Set objReg = New cRegSettings
strFile = "YourFilePathName"
objReg.SaveSetting "software\adobe\acrobat pdfwriter", "PDFFileName",
REG_SZ, strFile

Hope this helps.
 
Back
Top