Reports as PDFs

G

Guest

Hello,

I need to be able to save a selection of reports automatically as PDFs to my
local drive. How can this be done? I would like to somehow click a button
that would take those report names and automatically save them down to my
hard drive as PDF files. Is there an easy way to do this? I have about 6
reports.

Thank you!
MN
 
G

Guest

Sure...if you have Adobe Acrobat, not the Reader, you can do this. However,
if you would let us know what version of Access you are using along with what
version of Acrobat you have, I can post a solution. The solution varies
depending on the versions of Office and Acrobat.
 
D

Douglas J. Steele

Stephen is an awesome coder on his worst days! And it's only a hobby for
him...
 
G

Guest

That is impressive.

Hey, do you know where in the code I would add the path of where I want the
documents saved instead of defaulting to the mydocuments folder?

Thanks!
 
D

Douglas J. Steele

Sorry, not off the top of my head, and I'm afraid I don't have access to
anything other than Access 97 on this machine, so I can't check the code.
 
G

Guest

No problem! I was able to hunt down the portion of the code where it brings
up a new filename and path dialog box. (had to change a parameter to "YES")
However, there must be a way to hard code a pathname, so i don't have to save
each one down individually to the same place.

Thanks!
MN
 
D

Douglas J. Steele

How is Stephen invoking the dialog box? I'd assume he's using the standard
Windows GetSaveFileName API call. If that's the case, you can pass it a
starting folder.
 
G

Guest

This is where the call occurs:

Dim blRet As Boolean
' Call our convert function
' Please note the last param signals whether to perform
' font embedding or not. I have turned font embedding ON for this example.
blRet = ConvertReportToPDF(Me.lstRptName, vbNullString, _
Me.lstRptName.Value & ".pdf", True, True, 0, "", "", 0, 0)
' To modify the above call to force the File Save Dialog to select the name
and path
' for the saved PDF file simply change the ShowSaveFileDialog param to TRUE.

End Sub

Thanks,
MN
 
D

Douglas J. Steele

No, that's not what I'm looking for.

Once you've changed the ShowSaveFileDialog to True, it must invoke code
within ConvertReportToPDF. Go into that function, and do a search to see
where it checks the value of ShowSaveFileDialog.
 
G

Guest

Looks at the else statement in this code...

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
sOutFile = OutputPDFname
End If

Else
' Call File Save Dialog
sOutFile = fFileDialog()
If Len(sOutFile & vbNullString) = 0 Then
Exit Function
End If

End If
 
D

Douglas J. Steele

We're getting there! (sorry I can't look these things up myself...)

What's the definition of sFileDialog()? (Paste the entire function if it's
not too big)
 
G

Guest

Oh no problem at all, I'm thrilled that you are trying to help me! :)

Here is the fFileDialog function:

Private Function fFileDialog() As String
' Calls the API File Save Dialog Window
' Returns full path to new File

On Error GoTo Err_fFileDialog

' Call the File Common Dialog Window
Dim clsDialog As Object
Dim strTemp As String
Dim strFname As String

Set clsDialog = New clsCommonDialog

' Fill in our structure
' I'll leave in how to select Gif and Jpeg to
' show you how to build the Filter in case you want
' to use this code in another project.
clsDialog.Filter = "PDF (*.PDF)" & Chr$(0) & "*.PDF" & Chr$(0)
'clsDialog.Filter = clsDialog.Filter & "Gif (*.GIF)" & Chr$(0) & "*.GIF" &
Chr$(0)
'clsDialog.Filter = "ALL (*.*)" & Chr$(0) & "*.*" & Chr$(0)
clsDialog.hDC = 0
clsDialog.MaxFileSize = 256
clsDialog.Max = 256
clsDialog.FileTitle = vbNullString
clsDialog.DialogTitle = "Please Select a path and Enter a Name for the PDF
File"
clsDialog.InitDir = vbNullString
clsDialog.DefaultExt = vbNullString

' Display the File Dialog
clsDialog.ShowSave

' See if user clicked Cancel or even selected
' the very same file already selected
strFname = clsDialog.FileName
'If Len(strFname & vbNullString) = 0 Then
' Raise the exception
' Err.Raise vbObjectError + 513, "clsPrintToFit.fFileDialog", _
'"Please type in a Name for a New File"
'End If

' Return File Path and Name
fFileDialog = strFname

Exit_fFileDialog:

Err.Clear
Set clsDialog = Nothing
Exit Function

Err_fFileDialog:
fFileDialog = ""
MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
Resume Exit_fFileDialog

End Function
 
D

Douglas J. Steele

Ok, so it looks as though Stephen's created a class called clsCommonDialog.

Replace vbNullString in the line

clsDialog.InitDir = vbNullString

to wherever you want to start the dialog.
 
G

Guest

am i to then insert the path of where i want every document saved? (put that
path in quotes) and when i tried executing the code, there was no document in
that folder i had the path pointing to.
 
G

Guest

I actually tried it again and it DID work! Any way to maek that process
completely animated, not having to bring up that dialog box at all and force
it to save to that folder withi the report name as teh file name?
 
D

Douglas J. Steele

I'm sure it's doable.

What happens if you change the call from

blRet = ConvertReportToPDF(Me.lstRptName, vbNullString, _
Me.lstRptName.Value & ".pdf", True, True, 0, "", "", 0, 0)

to

blRet = ConvertReportToPDF(Me.lstRptName, vbNullString, _
"C:\Folder\" & Me.lstRptName.Value & ".pdf", True, True, 0, "", "", 0, 0)

(I assume one of those two "True" values corresponds to ShowSaveFileDialog:
you'll want to set it to False)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top