p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: Report to PDF


Message #1 by "George Oro" <george@c...> on Sat, 22 Jun 2002 09:17:07 +0400
Hi Guys,

How can I convert my report to PDF File using VBA? I really need this solution very badly...


Please help guys,
George ;(
Message #2 by "enZo :-\)" <enzaux@g...> on Sat, 22 Jun 2002 13:29:45 +0800
May be try reading command line option of Adobe acrobat if there's any

-----Original Message-----
From: George Oro [mailto:george@c...]
Sent: Saturday, June 22, 2002 1:17 PM
To: Access
Subject: [access] Report to PDF


Hi Guys,

How can I convert my report to PDF File using VBA? I really need this solution very badly...


Please help guys,
George ;(




Message #3 by "John Ruff" <papparuff@c...> on Fri, 21 Jun 2002 22:52:07 -0700
George,

Did you check out the the web-site www.pdf995.com I told you about last
month?  The pdf995 and pdfEdit995 downloads will permit you to create
pdf files without having to have Adobe Acrobat.

After purchasing pdf995, pdfEdit995 and Signature995, I asked pdf for
help.  Here is my request and then their answer on automatically
creating pdf files:

Sent: Friday, May 31, 2002 7:51 AM
Subject: Automatically Generating a PDF File Through MS Access


I recently purchased your Suite License.  I am trying to create pdf file
automatically through MS Access.  My reports has PDF995 it's printer and
when I go to print the report via code, the Save As dialog box pops up
asking me what directory to save it in and what file name.  Is there a
way that I can programatically tell the program the directory and file
name to use?
 
The followng code will automatically print the report when I press a
button on a form when I have the Printer set to a Printer and not
PDF995.
 
    Dim strDir As String
    Dim strFile As String
    
    strDir = "C:\Documents and Settings\John\My Documents\My Work\PDF
Report Files\"
    strFile = Format(Now(), "hh-nn") & ".pdf"
    DoCmd.OpenReport "rptBirthdays", acViewNormal

How can I have the program automatically create the pdf file and place
it in the strDir directory with the strFile name.
 
They replied with:

John,
 
PdfEdit has autoname features. I recommend setting the PDF to be named
based on the document being printed. Create a temporary report with the
name of the PDF you want and tell it to print to PDF995. The Save As
dialog won't appear.
 
-pdf995 Support
 

Here is the code I use to create the pdf file:

Private Sub cmdPrint_Click()
' If you don't want the report dialog box being displayed
' asking what name you want to give the pdf report, you will
' need pdfEdit995.  With pdfEdit995t you tell pdf995 what directory
' and what file name to initially give the pdf report.
'
' Quote from PDF; "pdfEdit995 has autoname features. I recommend setting
' the PDF to be named based on the document being printed. Create a
' temporary report with the name of the PDF you want and tell it to
' print to PDF995. The Save As dialog won't appear."

    Dim strDir As String
    Dim strFile As String
    Dim fOK As Boolean
    
    ' Directory to place the PDF files that are to
    ' be printed
    strDir = "C:\Documents and Settings\John\My Documents\My Work\PDF
Report Files\"
    ' Name of file to create
    strFile = Format(Now(), "hh-nn") & ".pdf"
    ' Create the report
    DoCmd.OpenReport "rptBirthdays", acViewNormal
    ' Copy the created file (name is Output.pdf) to the
    ' directory and file name specified above
    fOK = CopyFile_TSB(strDir & "Output.pdf", strDir & strFile)
    ' If the file didn't copy properly, tell the user
    If Not fOK Then
        Beep
        MsgBox "File Copy Failure"
    End If
    
End Sub

John V. Ruff - The Eternal Optimist :-)
Always Looking for Contract Opportunities

www.noclassroom.com

Home:  xxx.xxx.xxxx
Cell:  xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 
 
"Commit to the Lord whatever you do,
    and your plans will succeed."  Proverbs 16:3


-----Original Message-----
From: George Oro [mailto:george@c...] 
Sent: Friday, June 21, 2002 10:17 PM
To: Access
Subject: [access] Report to PDF


Hi Guys,

How can I convert my report to PDF File using VBA? I really need this
solution very badly...


Please help guys,
George ;(


Message #4 by "John Ruff" <papparuff@c...> on Fri, 21 Jun 2002 22:58:18 -0700
George,

You will also need this function if you try my solution.

Function CopyFile_TSB(strSource As String, strDestination As String) As
Boolean
    ' Comments  : copies a file
    ' Parameters: strSource - source file
    '             strDestination - destination file
    ' Returns   : True if successful, False otherwise
    '
    Const BufferSize = 4096

    Dim strBuffer As String * BufferSize
    Dim strTempBuffer As String
    Dim intSourceFile As Integer
    Dim intDestinationFile As Integer
    Dim lngCounter As Long

    On Error GoTo PROC_ERR
    
    intSourceFile = FreeFile
    Open strSource For Binary As #intSourceFile
    
    intDestinationFile = FreeFile
    Open strDestination For Binary As #intDestinationFile
    
    For lngCounter = 1 To LOF(intSourceFile) \ BufferSize
        Get #intSourceFile, , strBuffer
        Put #intDestinationFile, , strBuffer
    Next lngCounter
    
    lngCounter = LOF(intSourceFile) Mod BufferSize
    
    If lngCounter > 0 Then
        Get #intSourceFile, , strBuffer
        strTempBuffer = Left$(strBuffer, lngCounter)
        Put #intDestinationFile, , strTempBuffer
    End If

    Close #intSourceFile
    Close #intDestinationFile
    CopyFile_TSB = True
    
PROC_EXIT:
    Exit Function
    
PROC_ERR:
    CopyFile_TSB = False
    Resume PROC_EXIT
    
End Function

John V. Ruff - The Eternal Optimist :-)
Always Looking for Contract Opportunities

www.noclassroom.com

Home:  xxx.xxx.xxxx
Cell:  xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 
 
"Commit to the Lord whatever you do,
    and your plans will succeed."  Proverbs 16:3


-----Original Message-----
From: George Oro [mailto:george@c...] 
Sent: Friday, June 21, 2002 10:17 PM
To: Access
Subject: [access] Report to PDF


Hi Guys,

How can I convert my report to PDF File using VBA? I really need this
solution very badly...


Please help guys,
George ;(


Message #5 by "enZo :-\)" <enzaux@g...> on Sat, 22 Jun 2002 14:06:36 +0800
Ey nice bible verse, that was one of my favorite verse in the Bible :)

-----Original Message-----
From: John Ruff [mailto:papparuff@c...]
Sent: Saturday, June 22, 2002 1:58 PM
To: Access
Subject: [access] RE: Report to PDF


George,

You will also need this function if you try my solution.

Function CopyFile_TSB(strSource As String, strDestination As String) As
Boolean
    ' Comments  : copies a file
    ' Parameters: strSource - source file
    '             strDestination - destination file
    ' Returns   : True if successful, False otherwise
    '
    Const BufferSize = 4096

    Dim strBuffer As String * BufferSize
    Dim strTempBuffer As String
    Dim intSourceFile As Integer
    Dim intDestinationFile As Integer
    Dim lngCounter As Long

    On Error GoTo PROC_ERR
    
    intSourceFile = FreeFile
    Open strSource For Binary As #intSourceFile
    
    intDestinationFile = FreeFile
    Open strDestination For Binary As #intDestinationFile
    
    For lngCounter = 1 To LOF(intSourceFile) \ BufferSize
        Get #intSourceFile, , strBuffer
        Put #intDestinationFile, , strBuffer
    Next lngCounter
    
    lngCounter = LOF(intSourceFile) Mod BufferSize
    
    If lngCounter > 0 Then
        Get #intSourceFile, , strBuffer
        strTempBuffer = Left$(strBuffer, lngCounter)
        Put #intDestinationFile, , strTempBuffer
    End If

    Close #intSourceFile
    Close #intDestinationFile
    CopyFile_TSB = True
    
PROC_EXIT:
    Exit Function
    
PROC_ERR:
    CopyFile_TSB = False
    Resume PROC_EXIT
    
End Function

John V. Ruff - The Eternal Optimist :-)
Always Looking for Contract Opportunities

www.noclassroom.com

Home:  xxx.xxx.xxxx
Cell:  xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 
 
"Commit to the Lord whatever you do,
    and your plans will succeed."  Proverbs 16:3


-----Original Message-----
From: George Oro [mailto:george@c...] 
Sent: Friday, June 21, 2002 10:17 PM
To: Access
Subject: [access] Report to PDF


Hi Guys,

How can I convert my report to PDF File using VBA? I really need this
solution very badly...


Please help guys,
George ;(






Message #6 by "George Oro" <george@c...> on Sat, 22 Jun 2002 11:05:06 +0400
This is excellent tips and solution John!!

Many, many thanks...


Cheers
George :)



-----Original Message-----
From: John Ruff [mailto:papparuff@c...]
Sent: Saturday, June 22, 2002 9:58 AM
To: Access
Subject: [access] RE: Report to PDF


George,

You will also need this function if you try my solution.

Function CopyFile_TSB(strSource As String, strDestination As String) As
Boolean
    ' Comments  : copies a file
    ' Parameters: strSource - source file
    '             strDestination - destination file
    ' Returns   : True if successful, False otherwise
    '
    Const BufferSize = 4096

    Dim strBuffer As String * BufferSize
    Dim strTempBuffer As String
    Dim intSourceFile As Integer
    Dim intDestinationFile As Integer
    Dim lngCounter As Long

    On Error GoTo PROC_ERR
    
    intSourceFile = FreeFile
    Open strSource For Binary As #intSourceFile
    
    intDestinationFile = FreeFile
    Open strDestination For Binary As #intDestinationFile
    
    For lngCounter = 1 To LOF(intSourceFile) \ BufferSize
        Get #intSourceFile, , strBuffer
        Put #intDestinationFile, , strBuffer
    Next lngCounter
    
    lngCounter = LOF(intSourceFile) Mod BufferSize
    
    If lngCounter > 0 Then
        Get #intSourceFile, , strBuffer
        strTempBuffer = Left$(strBuffer, lngCounter)
        Put #intDestinationFile, , strTempBuffer
    End If

    Close #intSourceFile
    Close #intDestinationFile
    CopyFile_TSB = True
    
PROC_EXIT:
    Exit Function
    
PROC_ERR:
    CopyFile_TSB = False
    Resume PROC_EXIT
    
End Function

John V. Ruff - The Eternal Optimist :-)
Always Looking for Contract Opportunities

www.noclassroom.com

Home:  xxx.xxx.xxxx
Cell:  xxx.xxx.xxxx
9306 Farwest Dr SW
Lakewood, WA 98498 
 
"Commit to the Lord whatever you do,
    and your plans will succeed."  Proverbs 16:3


-----Original Message-----
From: George Oro [mailto:george@c...] 
Sent: Friday, June 21, 2002 10:17 PM
To: Access
Subject: [access] Report to PDF


Hi Guys,

How can I convert my report to PDF File using VBA? I really need this
solution very badly...


Please help guys,
George ;(





  Return to Index