Link to home
Start Free TrialLog in
Avatar of Shooter54
Shooter54

asked on

Dynamic PDF filename on export

I have a function in a basic module that is being called from a custom ribbon tag, for which the code reads:

   strFileName = SaveFileName(strFileType, strFileType, strFileFilter)
   If strFileName <> "" Then
      DoCmd.OutputTo acOutputReport, Screen.ActiveReport.Name, strFileType, strFileName
     
   End If

It works beautifully, however I would like the default filename to be something like "FacListNum" & Me.FacListNum, with FacListNum being the name of a control or field on my report. As it is, it uses the name of the report rather than dynamically naming it according to the value of my field or control. Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or this to make the file type dynamic

  strFileName = SaveFileName(strFileType, strFileType, strFileFilter)

strFileName=Left(strFileName, instr(strFileName, ".")-1) & "_" & Me.FacListNum & mid(strFileName,instrrev(strFileName,"."))


   If strFileName <> "" Then
      DoCmd.OutputTo acOutputReport, Screen.ActiveReport.Name, strFileType, strFileName
     
   End If
Something to try, and to keep in mind.
Reports (and forms) have a .Caption property
Set this in the Open() event of the report and if the user prints to PDF, or saves as PDF, the caption will be the suggested filename.
For Forms, the caption is displayed in the title bar or tab title.  You can mess with that in the Current() event to dynamically update
And, if they are printing to paper, the caption becomes the name of the print job in the printer queue.
That can be a convenience if multiple users are printing to the same printer and the printer can display its queue (like my big Ricohs can) or on the Windows boxes, when you open up a print queue and see what's in there if print jobs are stalled or paused.