Solved Print Report As PDF file

Rania01

Member
Local time
Today, 23:18
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: 140
Last edited:
That code cannot work because Me.Invoice Number has a space.

What values do the two controls contain?

What does voor mean?
 
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
 
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?
 
you can also change the ControlSource of InvoiceNumber textbox:

="Invoice Number R" & (10000 + [Invoice])
 
Thank you arnelqp and June for your help

I use de VBA from arnelqp is working
 

Users who are viewing this thread

Back
Top Bottom