How to save report with a specific name each time (1 Viewer)

mkdrep

Registered User.
Local time
Today, 18:18
Joined
Feb 6, 2014
Messages
176
Currently when I go to save a report in (.pdf) form to email out, the default file name to "save as" is always: "rpt_SL_Job_Notify.pdf". This is the name of the underlying report I created. (see attached: Save_Document-1.jpg)

What I would like to have happen is to have the default file name "save as" the actual [JobTrackNo], (see attached: Save_Document-JTNmbr-Field.jpg) which is the field name for the info I want created as a (.pdf).

In this particular case, I would like the "save as" come up as "201300573002", (see attached: Save_Document-JTNmbr.jpg).

This would save me a lot of time as I wouldn't have to type over "rpt_SL_Job_Notify.pdf" each time before I saved the file.

Any suggestions on how I could do this? thank you.

Mark
 

Attachments

  • Save_Document-1.jpg
    Save_Document-1.jpg
    7.6 KB · Views: 53
  • Save_Document-JTNmbr.jpg
    Save_Document-JTNmbr.jpg
    2.2 KB · Views: 42
  • Save_Document-JTNmbr-Field.jpg
    Save_Document-JTNmbr-Field.jpg
    2.6 KB · Views: 44

Gasman

Enthusiastic Amateur
Local time
Today, 23:18
Joined
Sep 21, 2011
Messages
14,238
I've done this by copying the report to a name I would like to use and then saving that.

This was because the db was created in Access 2003 and I had no facility to print to pdf with a name. By naming the report, the pdf writer automaticall takes that as the default name.

HTH

Code:
Private Sub cmdShip_Click()
On Error GoTo Err_cmdShip_Click

    Dim stRptName As String, stParam As String, stLinkCriteria As String
    Dim iPreview As Integer, iDialog As Integer
    
    iPreview = 0
    iDialog = 0
    If Me.ChkPreview Then
        iPreview = 2
        iDialog = 3
    End If
    stRptName = "Main_by_Ship"
    
    stParam = Replace(LCase(Me.cboShip.value), " ", "_")
    stLinkCriteria = "[Ship] = '" & Me.cboShip.value & "'"
    
    DoCmd.CopyObject , stParam, acReport, stRptName
    DoCmd.OpenReport stParam, iPreview, , stLinkCriteria, iDialog

    DoCmd.Close acReport, stParam
    DoCmd.DeleteObject acReport, stParam

Exit_cmdShip_Click:
    Exit Sub

Err_cmdShip_Click:
    MsgBox Err.description
    Resume Exit_cmdShip_Click
    
End Sub
 

MarkK

bit cruncher
Local time
Today, 15:18
Joined
Mar 17, 2004
Messages
8,180
DoCmd.OutputTo allows you name the output file . . .
Code:
DoCmd.OutputTo(ObjectType, ObjectName, OutputFormat, [COLOR="Blue"]OutputFile[/COLOR], AutoStart, TemplateFile, Encoding, OutputQuality)
To control what records appear in a report printed this way, design the report to consume a named query. Then programmatically modify that query to return the records you want the report to show, then run OutputTo.
 

mkdrep

Registered User.
Local time
Today, 18:18
Joined
Feb 6, 2014
Messages
176
I've done this by copying the report to a name I would like to use and then saving that.

This was because the db was created in Access 2003 and I had no facility to print to pdf with a name. By naming the report, the pdf writer automaticall takes that as the default name.

HTH

Code:
Private Sub cmdShip_Click()
On Error GoTo Err_cmdShip_Click

    Dim stRptName As String, stParam As String, stLinkCriteria As String
    Dim iPreview As Integer, iDialog As Integer
    
    iPreview = 0
    iDialog = 0
    If Me.ChkPreview Then
        iPreview = 2
        iDialog = 3
    End If
    stRptName = "Main_by_Ship"
    
    stParam = Replace(LCase(Me.cboShip.value), " ", "_")
    stLinkCriteria = "[Ship] = '" & Me.cboShip.value & "'"
    
    DoCmd.CopyObject , stParam, acReport, stRptName
    DoCmd.OpenReport stParam, iPreview, , stLinkCriteria, iDialog

    DoCmd.Close acReport, stParam
    DoCmd.DeleteObject acReport, stParam

Exit_cmdShip_Click:
    Exit Sub

Err_cmdShip_Click:
    MsgBox Err.description
    Resume Exit_cmdShip_Click
    
End Sub

Thank you for the suggestion. I will give it a try.
 

Users who are viewing this thread

Top Bottom