We help IT Professionals succeed at work.

Dynamic PDF filename on export

Shooter54
Shooter54 asked
on
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.
Comment
Watch Question

Top Expert 2016
Commented:
test this  

strFileName = SaveFileName(strFileType, strFileType, strFileFilter)
   If strFileName <> "" Then

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

      DoCmd.OutputTo acOutputReport, Screen.ActiveReport.Name, strFileType, strFileName
     
   End If
Top Expert 2016

Commented:
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
Most Valuable Expert 2014

Commented:
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.