Reputation: 1
I am wanting to export from an Access report to a pdf who name is governed by the data within the report.
I have created the code below but it is only saving the file as _.pdf
and not the values I want.
I have the report open when ruinning this. It looks as though the data from the report isnt coming through to the code but I'm not sure how and if this is correct.
Could someone help me in as plain english as possible. Many thanks
Sub outputpdf()
Dim myPath As String
Dim strReportName As String
Dim stritem As String
Dim strcont As String
Dim strid As String
Dim struniq As String
DoCmd.OpenReport "outputreport", acViewPreview
myPath = "D:\simon\test\"
strReportName = stritem + strcont + ".pdf"
'strReportName = Item + contract_number + "_"+ ".pdf"
DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath & strReportName, False
DoCmd.Close acReport, "outputreport"
End Sub
Upvotes: 0
Views: 30642
Reputation: 1212
Access and VBA concatenation use the &
operator and not +
like C languages.
strReportName = stritem + strcont + ".pdf"
To
strReportName = strItem & strcont & ".pdf"
You have it right in the bottom part, I think...
Edit:
build it
Sub ObjectBuilder()
Dim item As String, cont As String
item = InputBox("Enter Item", "Item", "12345")
cont = InputBox("Enter Container?", "Container", "Shipping Crate")
OutputPdf item, cont
End Sub
Then use it
Sub OutputPdf(item As String, cont As String)
'your code
strItem = item
strCont = cont
End Sub
Upvotes: 1