Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PDF report using code to specify path and report name

Status
Not open for further replies.

abundantlyfe

Technical User
May 21, 2007
8
GB
Hi there.

I have some code which enables the user to specify a report name, then PDF the report and save it in the correct folder with the name specified by the user. However, when I run the code it doesn't save with the name specified, but with the actual name of the report.

I'm lost! I don't know what is going wrong, so any help would be appreciated.

Thank you.

Public Function PrintReportToPDF() As Boolean
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Purpose: Print a report to a PDF file
'
' Inputs: strReport Name of report
' strSave Name of PDF file to create
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On Error GoTo ErrHandler
Dim strReport As String
Dim strSave As String
Dim strNewRpt As String
' create the registry entry to set PDF path and filename
strSave = InputBox("Please Enter File Name", "Save PDF") ' & ".PDF"
strReport = "Rpt_Results"
strNewRpt = strSave

WriteRegistryEntry strSave

' print the report - CHECK THE PRINTER NAME IS CORRECT
Set Application.Printer = Application.Printers("Acrobat PDFWriter")
DoCmd.CopyObject , strNewRpt, acReport, strReport
DoCmd.Close acReport, strReport, acSaveNo
DoCmd.OpenReport strNewRpt, acViewNormal
DoCmd.DeleteObject acReport, strNewRpt
Application.Printer = Nothing

PrintReportToPDF = True
'Kill strPath & "CreatePDF.reg"

ExitHere:
Exit Function

ErrHandler:
MsgBox Err.Description
Resume ExitHere
End Function

Public Function WriteRegistryEntry(strPDF As String)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Purpose: Create a registry file in order to set the name and path
' of the PDF file
'
' Reference: Concept developed from post at
' '
' Assumptions: Registry file is created in same folder as current database,
' then deleted once it has been merged into the registry
'
' Inputs: strPDF Name of PDF file to create
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Dim strPath As String
Dim x


strPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\", , vbTextCompare))

' make sure reports folder exists
If Dir(strPath & "Reports\", vbDirectory) = "" Then
MkDir strPath & "Reports\"
End If

' registry key needs "\\" in file path
strPDF = strPath & "Reports\" & strPDF & ".PDF"
strPDF = Replace(strPDF, "\", "\\")

' delete the registry file if it exists
On Error Resume Next
Kill strPath & "CreatePDF.reg"

' create the registry file
On Error GoTo ErrHandler
Open strPath & "CreatePDF.reg" For Append As #1

Print #1, "Windows Registry Editor Version 5.00"
Print #1, ""
Print #1, "[HKEY_CURRENT_USER\Software\Adobe\Acrobat PDFWriter]"
Print #1, """PDFFilename""=" & Chr(34) & strPDF & Chr(34)
Close #1

' merge into registry
x = Shell("regedit.exe /s " & strPath & "CreatePDF.reg", vbHide)


ExitHere:
On Error Resume Next
Close #1
Kill strPath & "CreatePDF.reg"
Exit Function

ErrHandler:
MsgBox Err.Description
Resume ExitHere
End Function

You can call me AL!

Crystal Reports for ESRI v 11
 
Hi Genomon

Unfortunately that link didn't work!

You can call me AL!

Crystal Reports for ESRI v 11
 
It's ok - worked it out!

The caption on the report had a value, so when I removed that value it saved with the name I wanted.

Thank you for your time.

You can call me AL!

Crystal Reports for ESRI v 11
 
Great! Sorry about the bum link. Their home page seems to be down as well:
There seems to have been a problem with the database.
Please try again by clicking the Refresh button in your web browser.

An E-Mail has been dispatched to our Technical Staff, whom you can also contact if the problem persists.

We apologise for any inconvenience.

I'll have to try again later...

Ever notice how fast Windows runs? Me neither.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top