Setting name of Report before PDFing

lovett10

Registered User.
Local time
Today, 14:35
Joined
Dec 1, 2011
Messages
150
Im looking to temporarily change the name of a report to the contents of Me.Combo16 & Me.Text18

Then change it back after PDFing to just Me.Combo16

Here is my code to PDF (which works perfectly atm)

Code:
Private Sub Command6_Click()
Application.Printer = Application.Printers("Adobe PDF")
DoCmd.OpenReport Me.Combo16
End Sub

The reason is so that the name is automatically set to save as the name + the date so they dont accidently overrite any previous saves

P.s the date is from the Me.Text18

Thanks in advance :)
 
I use this code to print to a .pdf:
Code:
stDocName = "Inspectors report"
DocName = strPath & rs!Job & "_" & Format(Date, "yyyymmdd") & ".pdf"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, DocName, False

Hi thanks for the reply Heres what i have...

Code:
Dim stDocName As String
Dim DocName As String
stDocName = Me.Combo16
DocName = Me.Combo16 & Me.Text18 & ".pdf"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, DocName, False

i get Run-time error '2501' The OutputTo action was canceled.
 
Ah ive figured out the problem it is because of invalid characters :) thanks again..

oh and is there a way of specifying where it saves too?
 
I use this code to print to PDF specifying name and location:

Dim strFile As String
Dim strDestPath As String
Dim strDestFile As String
Dim blnShowPdf As Boolean

strFile = "qryFinanceRepDateRange"
srrDestPath = "C:\Reports\"
strDestFile = "Finance Report By Date Range"
blnShowPdf = True

DoCmd.OutputTo acOutputReport, strFile, "PDFFormat(*.PDF)", strDestPath & strDestFile & ".pdf", blnShowPdf, "", 0, acExportQualityPrint
DoCmd.Close acReport, strFile
 
Hey thanks for the help.

Im getting the same error over and over...

Run-time error '2059'

Microsoft Access Cannot fins the object '|1'

Heres my code:
Code:
Private Sub Command6_Click()
Dim strFile As String
Dim strDestPath As String
Dim strDestFile As String
Dim blnShowPdf As Boolean
strFile = Me.Combo16 & " R"
strDestPath = "C:\"
strDestFile = Me.Combo16 & Me.Text18
blnShowPdf = True
DoCmd.OutputTo acOutputReport, strFile, "PDFFormat(*.PDF)", strDestPath & strDestFile & ".pdf", blnShowPdf, "", 0, acExportQualityPrint
DoCmd.Close acReport, strFile
End Sub
 
Are there any odd characters in your file name (strDestFile) ?
you wont be able to have characters like \ or /
 
also, I think this error is related to the query/report name that you are trying to send to PDF (strFile)

strFile = Me.Combo16 & " R"

What is the extra 'R' for?
 
also, I think this error is related to the query/report name that you are trying to send to PDF (strFile)

strFile = Me.Combo16 & " R"

What is the extra 'R' for?


I didnt originally have that it was just a test because the table and reports have the same name so i thought it may be geting confused so i added the " R" to one of the reports as a test... still gave me an error
 
I found the problem it was the saving to C drive when i just leave the pathfile to "" it works... ofcourse i still need to figure out how to choose the file :P
 
Aah sorry I forgot that the original question was to save a different file name.

I had the same problem when exporting to Excel - so I used the current time to save the file, the database then randomly adds a few numbers to the end of the file name, this way every file has a different name automatically.

So I have a reports data table with the 'queryname' in one column then a 'visible' reportname in another column so the user sees a nice easily readable title (see attached image reportname) reportname.JPG

On my form, I created a combo box to look up to the reports table and show the 'reportname' so the users read a meaningful name, I also added the queryname as a second column (see attached image combobox) combobox.JPG

I then have a submit button that runs the following code:

Dim strFile As String
Dim strDestPath As String
Dim strDestFile As String
Dim blnShowPdf As Boolean
Dim strQueryName As String
Dim strQueryVisName As String
Dim strReportTime As String

strReportTime = Int(CSng(Time * 1440)) 'obtains the current time and converts it to numbers

strQueryVisName = Me.cboReportName & " " & strReportTime 'takes the report name and adds the time
strQueryName = Me.cboReportName.Column(1) 'uses the query name to run the query itself

strFile = Me.cboReportName.Column(1) 'takes the queryname from the combo box
srrDestPath = "C:\Reports\" 'sets the destination folder
strDestFile = Me.cboReportName & " " & strReportTime 'uses the reportname and adds the time to the end of the file name
blnShowPdf = True

DoCmd.OutputTo acOutputReport, strFile, "PDFFormat(*.PDF)", strDestPath & strDestFile & ".pdf", blnShowPdf, "", 0, acExportQualityPrint
DoCmd.Close acReport, strFile

Hope this helps
 

Users who are viewing this thread

Back
Top Bottom