Change name to Report (1 Viewer)

JPR

Registered User.
Local time
Today, 11:57
Joined
Jan 23, 2009
Messages
192
Hello,
I have a form with a cmd button which executes a macro to export a report of this form via email as a pdf file.

The file shows the same name of the report (report1).
I was thinking to change it's name and have used a solution which have already uses with the printcurrentrecords on forms and orks great.
In the On Current event of the report have typed the following:

Private Sub Report_Current()
' Me.Caption = (Me.FNMAE) & " " & (Me.LNAME) & " - " & (Me.FileNo)
End Sub

What I would like is to rename the file in pdf with the records indicated below. Unfortunately, when I run the macro, it still shows the name of the reports (report1).
Thank you for any assistance.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:57
Joined
Sep 21, 2011
Messages
14,237
That is not changing the name though, just the caption.?
When I had to do something similar I just copied the report giving it the required name and then deleted it after the pdf was created.
 

JPR

Registered User.
Local time
Today, 11:57
Joined
Jan 23, 2009
Messages
192
Thank you Gasman,
would you assist me with some code? Thank you
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:57
Joined
Sep 21, 2011
Messages
14,237
Here is some code from that DB.
The actual code to copy and delete is now commented out as that was with 2003. With 2007 I am able to save a pdf with a particular name.

Code:
Private Sub cmdShip_Click()
On Error GoTo Err_cmdShip_Click

    Dim stRptName As String, stParam As String, stLinkCriteria As String, stDBpath As String, stFTPpath As String
    Dim iPreview As Integer, iDialog As Integer
    
    stDBpath = CurrentProject.Path & "\"
    stFTPpath = stDBpath & "Gazette\"
    iPreview = 0
    iDialog = 0
    iPreview = acViewPreview
    If Me.ChkPreview Then
       ' iPreview = 2
        iDialog = acWindowNormal
    Else
        iDialog = acHidden
    End If
    
    stRptName = "Main_by_Ship"
    
    stParam = Replace(LCase(Me.cboShip.Value), " ", "_")
    stLinkCriteria = "[Ship] = '" & Me.cboShip.Value & "'"
    
    'DoCmd.CopyObject , stParam, acReport, stRptName
    DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
    DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stFTPpath & stParam & ".pdf", False
    DoCmd.Close acReport, stRptName
    'DoCmd.DeleteObject acReport, stParam

Exit_cmdShip_Click:
    Exit Sub

Err_cmdShip_Click:
    MsgBox Err.Description
    Resume Exit_cmdShip_Click
    
End Sub
 

Users who are viewing this thread

Top Bottom