Solved Print Report As PDF file (1 Viewer)

Rania01

Member
Local time
Today, 22:58
Joined
Oct 9, 2021
Messages
59
Dear All,

With below vba when i print the report i get result Invoice Number 1.PDF ( voor invoice number 1)

I Would like the result is : Invoice Number R10001.PDF (see fictur)


Code:
Private Sub PRINtPDF_Click()

Dim FileName As String
Dim FilePath As String

FileName = Me.Invoice Number & " " & Me.Invoice
FilePath = "C:\Data 2023\" & FileName & ".PDF"

On Error Resume Next
Kill FilePath
On Error GoTo 0
DoCmd.OpenReport ReportName:="DataReport", View:=acViewPreview, WindowMode:=acHidden, WhereCondition:="[Imvoice]=" & Me![Invoice]
DoCmd.OutputTo acOutputReport, "DataReport", acFormatPDF, FilePath
MsgBox "Done", vbInformation, "Save Confirm"


DoCmd.Close acReport, "DataReport", acSaveNo

End Sub
 

Attachments

  • Invoice.jpg
    Invoice.jpg
    79.8 KB · Views: 95
Last edited:

June7

AWF VIP
Local time
Today, 12:58
Joined
Mar 9, 2014
Messages
5,497
That code cannot work because Me.Invoice Number has a space.

What values do the two controls contain?

What does voor mean?
 

Rania01

Member
Local time
Today, 22:58
Joined
Oct 9, 2021
Messages
59
That code cannot work because Me.Invoice Number has a space.

What values do the two controls contain?

What does voor mean?

me.InvoiceNumber = textboxt with default value = Invoice Number
me.Invoice = AutoNumber from the invoice

On table invoice format "R"0000 en on form invoice format "R"0000
 

June7

AWF VIP
Local time
Today, 12:58
Joined
Mar 9, 2014
Messages
5,497
Interesting, how did your posted code end up with a space in control name?

Use Format() function to format number value. Format(Me.Invoice, "R10000")

Why does the invoice format show "R"0000 yet your desired output has R10001?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:58
Joined
May 7, 2009
Messages
19,246
you can also change the ControlSource of InvoiceNumber textbox:

="Invoice Number R" & (10000 + [Invoice])
 

Rania01

Member
Local time
Today, 22:58
Joined
Oct 9, 2021
Messages
59
Thank you arnelqp and June for your help

I use de VBA from arnelqp is working
 

Users who are viewing this thread

Top Bottom