abundantlyfe
Technical User
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
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