On 27 Dec 2005 10:18:16 -0800, "Tom" <rt*****@swbell.net> wrote:
Hi:
I'm using the Leban's ReportToPDF solution and have encountered a small
problem. I'm calling the code using the following:
Call ConvertReportToPDF(strReportName, , , True, True)
Where strReportname is the name of the report being printed.
I would like the Dialog box to be shown to allow the user to select a
path and file name (hence ShowSaveFileDialog =True).
I would also like to specify a default file name and path. I've tried
entering that in the 3rd parameter in the call statement, but it
appears as though if you set ShowSaveFileDialog = True, that overrides
whatever OutputPDFname is set to. It also appears that OutputPDFname
is limited to name only, not path and name.
I've tried modifying fFileDialog() to include the following lines when
setting up the clsDialog:
clsDialog.InitDir = PDFPath
clsDialog.FileName = PDFFileName
Where PDFPath and PDFFileName are both properties set in the calling
code. That works fine unless the user cancels the operation. Then it
proceeds to save the file anyway because it has a valid file name
courtesy of the default value.
So I added "clsDialog.CancelError = True" after the above lines hoping
that would catch the User Cancel and abort the whole operation.
However, the code appears not to check for the error that should be
raised.
Bottom line - I've about reached my depth here and could use some
pointers on how to solve this problem.
Thanks in advance.
Tom
I have been playing with this recently, looking at replacing Stephen Leban's ExportToMSWord to his new
ConvertReportToPDF in a particular application. (both excellent utilities Stephen).
I had a similar problem to yours and overcame it by adding an additional argument to the function ConvertReportToPDF
called DefaultPath.
Public Function ConvertReportToPDF( _
Optional RptName As String = "", _
Optional SnapshotName As String = "", _
Optional OutputPDFname As String = "", _
Optional ShowSaveFileDialog As Boolean = False, _
Optional StartPDFViewer As Boolean = True, _
Optional CompressionLevel As Long = 0, _
Optional PasswordOwner As String = "", _
Optional PasswordOpen As String = "", _
Optional PasswordRestrictions As Long = 0, _
Optional DefaultPath = "" _ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
) As Boolean
I then use GetOpenFileName to have the user select the destination path and filename for the PDF.
If the user cancels, GetOpenFileName will return "noFile" so I exit the procedure here without having to call
ConvertReportToPDF.
If a path and filename is returned, I call ConvertReportToPDF and send the path as the last argument and set the
ShowSaveFileDialog argument to false.
The following is a cut down version of the procedure I use which might give you the idea.
'==============================================
Dim strDefaultPath as String
Dim strRepName as String
Dim strFileName as String
Dim strPathAndFile as String
strRepName = "rptActionRequestPrintToFile"
strFileName = "ActionRequest_" & Format$(lngARNo, "0000")
If Len(strDefaultPath) = 0 Then
strPathAndFile = GetFilePathActionRequest(strFileName) '<<< returns path/filename or "noFile"
strDefaultPath = fGetDefaultPath(strPathAndFile) '<<< strips filename and leaves path only
Else
strPathAndFile = strDefaultPath & strFileName
End If
If strPathAndFile <> "noFile" Then
If ConvertReportToPDF(strRepName, , strFileName, False, False, , , , , strDefaultPath) = True Then '<<<<<<<<<
'success message
Else
'error message
End If
End If
'==============================================
In ConvertReportToPDF you will need to modify the following line -
If ShowSaveFileDialog = False Then
' let's decompress into same filename but change type to ".tmp"
' But first let's see if we were passed an output PDF file name
If Len(OutputPDFname & vbNullString) = 0 Then
sOutFile = Mid(strPathandFileName, 1, Len(strPathandFileName) - 3)
sOutFile = sOutFile & "PDF"
Else
'change this line from sOutFile = OutputPDFname to - '<<<<<<<<<<<<<<<<<<<<<
sOutFile = DefaultPath & OutputPDFname & ".PDF" '<<<<<<<<<<<<<<<<<<<<<<<
End If
Else
' Call File Save Dialog
sOutFile = fFileDialog()
If Len(sOutFile & vbNullString) = 0 Then
Exit Function
End If
End If
'==============================================
Function fGetDefaultPath(strIn As String) As String
'strips file name from strIn and returns path only
Dim x As Integer
Dim y As Integer
x = 1
Do Until x = 0
x = InStr(x, strIn, "\")
If x <> 0 Then y = x
If x <> 0 Then x = x + 1
Loop
fGetDefaultPath = Left(strIn, Len(strIn) - (Len(strIn) - y))
End Function
'==============================================
Wayne Gillespie
Gosford NSW Australia