Report Print Preview name

Seph

Member
Local time
Today, 18:22
Joined
Jul 12, 2022
Messages
72
Good day everyone,

Please can you assist me.

I have the following code which opens my reports InvoiceJobR/InvoiceSalesR in Print Preview, depending on the IIF criteria.

Code:
Private Sub InvoiceNumber_Click()

    DoCmd.OpenReport IIf(SalesInvoice, "InvoiceSalesR", "InvoiceJobR"), acViewPreview, , "InvoiceID=" & InvoiceID
     
End Sub

Screenshot 2023-01-24 192856.png


The code however, opens the report with the name of the report.

I'd like for it to open with the name of the InvoiceNumber field on the report so that when I print the report to PDF it reflects the invoice number.

Screenshot 2023-01-24 193250.png


Thank you in advance!
 
You just save the pdf with whatever name you like.
Otherwise copy the report as the new name and open tha and print it, then delete that report.
 
Another method is to open it in preview mode as you are (can be hidden), use OutputTo to save it with the desired name and path, then close the report.
 
You just save the pdf with whatever name you like.
Otherwise copy the report as the new name and open tha and print it, then delete that report.
I've been doing that. But it can be time consuming. Especially if there are alot of Invoices.
 
Well you are unlikely to get a tailor made block of code for your particular situation? :(
I tended to find something as close as possible or at least with the basics and amend to suit.

If you are not bothered about seeing the name in Preview, then this code can be amended to suit.
You have to do some of the work yourself, else you will never learn anything.

The code below created a report for a specific ship.
You can see I had to copy the report object as the ship name when on 2003, and then delete it.. When I obtained 2007, I could use the pdf option.

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, blnPrintIt As Boolean
    
    stDBpath = CurrentProject.Path & "\"
    stFTPpath = stDBpath & "Gazette\"
    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
        
    If Me.ChkPreview Then
        DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
    Else
        DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
        DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stFTPpath & stParam & ".pdf", False
        DoCmd.Close acReport, stRptName
    End If
    'DoCmd.DeleteObject acReport, stParam

Exit_cmdShip_Click:
    Exit Sub

Err_cmdShip_Click:
    MsgBox Err.Description
    Resume Exit_cmdShip_Click
    
End Sub
 
Well you are unlikely to get a tailor made block of code for your particular situation? :(
I tended to find something as close as possible or at least with the basics and amend to suit.

If you are not bothered about seeing the name in Preview, then this code can be amended to suit.
You have to do some of the work yourself, else you will never learn anything.

The code below created a report for a specific ship.
You can see I had to copy the report object as the ship name when on 2003, and then delete it.. When I obtained 2007, I could use the pdf option.

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, blnPrintIt As Boolean
   
    stDBpath = CurrentProject.Path & "\"
    stFTPpath = stDBpath & "Gazette\"
    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
       
    If Me.ChkPreview Then
        DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
    Else
        DoCmd.OpenReport stRptName, iPreview, , stLinkCriteria, iDialog
        DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stFTPpath & stParam & ".pdf", False
        DoCmd.Close acReport, stRptName
    End If
    'DoCmd.DeleteObject acReport, stParam

Exit_cmdShip_Click:
    Exit Sub

Err_cmdShip_Click:
    MsgBox Err.Description
    Resume Exit_cmdShip_Click
   
End Sub
Yeah I'm with you there.

The thing is though, the VBA aspect isn't where I shine.

I do appreciate the code and will do my best to cater it to my situation.
 
I'd like for it to open with the name of the InvoiceNumber field on the report so that when I print the report to PDF it reflects the invoice number.
add Code (VBA) on the Load Event of your Report:
bring your report in Design view.
and on the Load Event of the Report, choose Code Builder.
copy and paste the code:

Private Sub Report_Load()
Me.Caption = Me!InvoiceNumber
End Sub
 
add Code (VBA) on the Load Event of your Report:
bring your report in Design view.
and on the Load Event of the Report, choose Code Builder.
copy and paste the code:

Private Sub Report_Load()
Me.Caption = Me!InvoiceNumber
End Sub

You're amazing as always. Simple solutions are always easier to replicate and trouble shoot.

I appreciate everyone's input.
 
add Code (VBA) on the Load Event of your Report:
bring your report in Design view.
and on the Load Event of the Report, choose Code Builder.
copy and paste the code:

Private Sub Report_Load()
Me.Caption = Me!InvoiceNumber
End Sub
Ok, last question and then I won't ask another stupid question for a month:ROFLMAO:

Your code works perfectly. (Thank you)

I change the text field's format to get the desired result:

Screenshot 2023-01-25 115902.png


Screenshot 2023-01-25 120021.png

Is it possible to wrap the code in a format like it is in the Report Properties section so that the print preview shows the I000 as well?

Screenshot 2023-01-25 120806.png


I tried the below Code:

Code:
Private Sub Report_Load()

    Me.Caption = Me!InvoiceNumber.Format = "\I000000"
   
End Sub

But I get either True or False errors

Screenshot 2023-01-25 120911.png
 
try:

Me.Caption = Format$(Me!InvoiceNumber, "\I000000")
 

Users who are viewing this thread

Back
Top Bottom