By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

Lebans ReportToPDF solution Help

P: n/a
Tom
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

Dec 27 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If you want you could just not use the ReportToPDF class and use the
CutePDF Writer as the "printer" destination. Get the software from this
site:

http://tinyurl.com/dejty

Once set up all you have to do is "print" the report to the "printer"
named "Cute PDF Writer." A PDF file will be created.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQ7HGU4echKqOuFEgEQL+rgCg7pPdupgjV48nfKVQ6pyuDf MXbcwAn3M8
I6dsnrPBbOaJJ+3oe6ng/Kbc
=K1ru
-----END PGP SIGNATURE-----
Tom 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.

Dec 27 '05 #2

P: n/a
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
Dec 28 '05 #3

P: n/a
Thanks for helping out Wayne!

WIthin the next one or two releases I will encapsulate the code and expose
all of the necessary props. The current function call signature is getting
way too large and unwieldy. The project is still in Beta and it shows.
:-)

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Wayne Gillespie" <be*****@NOhotmailSPAM.com.au> wrote in message
news:ta********************************@4ax.com...
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

Dec 28 '05 #4

P: n/a
Tom
Excellent - thanks for the pointers Wayne, I'll give it a try tomorrow
morning.

Also thanks for the original solution Stephen. It was wonderfully easy
(at least until I started messing with it!) and help tremendously with
my project.

Tom

Dec 28 '05 #5

P: n/a
Tom there is a new release coming shortly(hopefully the final BETA version)
and then the first production release should be available shortly
thereafter. I have received comments from several hundred users and have
incorporated the most common feature requests into the next release. And
yes, many users requested that I expose default path/filename props along
with the final output path/filename. I'm working on this now but honestly
will not have time to finish the code until after New Years.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Tom" <rt*****@swbell.net> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Excellent - thanks for the pointers Wayne, I'll give it a try tomorrow
morning.

Also thanks for the original solution Stephen. It was wonderfully easy
(at least until I started messing with it!) and help tremendously with
my project.

Tom

Dec 28 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.