Printing report to .pdf

  • Thread starter Thread starter esimorp
  • Start date Start date
E

esimorp

Guest
Help....printing report to .pdf

Hi,

This is forum has been very helpful to me on my latest database project. I'm now stuck and hoping you all can help me out. This is an urgent request so hopefully someone here has dealt with the same problem. :)

First off, I hope I'm posting in the right forum.

I'm printing a report to .pdf. I'm using pdf995 and pdf995edit. Upon creating the file, I have code that automatically attaches the file to an e-mail. Everything works great, but I'm finding that after the code executes, the pdf995 printer remains the default. Ideally, I would like the code to execute, print to the pdf995 printer and reset the default printer to the applicable network printer. This is also running across a network. The pdfwriter is on the client, while the database is on a server. Here's the code I'm using now.

Code:
Private Sub btnEmail_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 = "D:\Documents and Settings\Heather\My Documents\Outsourced Projects\Tyco\"
    ' Name of file to create
    strFile = "DFM Summary Statistics Queried " & Format(Date, "Long Date") & ".pdf"
  
    ' Create the report
    DoCmd.OpenReport "rptStats", 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
SendMessage (strDir & strFile)
End Sub

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 = 9000


    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

Private Sub btnCancel_Click()
On Error GoTo Err_btnCancel_Click

    Dim stDocName As String

    stDocName = "CustStatsSelect.Cancel"
    DoCmd.RunMacro stDocName

Exit_btnCancel_Click:
    Exit Sub

Err_btnCancel_Click:
    MsgBox Err.Description
    Resume Exit_btnCancel_Click
    
End Sub

Sub SendMessage(Optional AttachmentPath)

           Dim objOutlook As Outlook.Application

               Dim objOutlookMsg As Outlook.MailItem

               Dim objOutlookRecip As Outlook.Recipient

               Dim objOutlookAttach As Outlook.Attachment



               ' Create the Outlook session.

               Set objOutlook = CreateObject("Outlook.Application")



           ' Create the message.

           Set objOutlookMsg = objOutlook.CreateItem(olMailItem)



           With objOutlookMsg

              ' Add the To recipient(s) to the message.

             Set objOutlookRecip = .Recipients.Add("heather@digitalcampground.com")

              objOutlookRecip.Type = olTo


              ' Add the CC recipient(s) to the message.

              Set objOutlookRecip = .Recipients.Add(" ")

              objOutlookRecip.Type = olCC



              ' Set the Subject, Body, and Importance of the message.

              .Subject = "DFM Statistics Summary"

              .Body = ""

              .Importance = olImportanceHigh  'High importance



              ' Add attachments to the message.
                Dim strFile As String
                strFile = "D:\Documents and Settings\Heather\My Documents\Outsourced Projects\Tyco\DFM Summary Statistics Queried " & Format(Date, "Long Date") & ".pdf"


              If Not IsMissing(AttachmentPath) Then

                 Set objOutlookAttach = .Attachments.Add(strFile)

              End If



              ' Resolve each Recipient's name.

              For Each objOutlookRecip In .Recipients

                 objOutlookRecip.Resolve

                 If Not objOutlookRecip.Resolve Then

                 objOutlookMsg.Display

              End If

              Next

              .Display



           End With

           Set objOutlookMsg = Nothing

           Set objOutlook = Nothing

        End Sub

I appreciate any help you can give me!

Thanks in Advance :)

Heather
 
I am not an expert, but i found another solution... i wrote the file directly to a .snp file, then used a program called Adlib Express to batch convert the .snp files to pdf to another directory on my network....

http://www.adlibsys.com/
 
Re: Help....printing report to .pdf

esimorp said:
I'm printing a report to .pdf. I'm using pdf995 and pdf995edit. Upon creating the file, I have code that automatically attaches the file to an e-mail. Everything works great, but I'm finding that after the code executes, the pdf995 printer remains the default. Ideally, I would like the code to execute, print to the pdf995 printer and reset the default printer to the applicable network printer. This is also running across a network. The pdfwriter is on the client, while the database is on a server.
Was this ever solved? I also use pdf995.
Cameroncha said:
I am not an expert, but i found another solution... i wrote the file directly to a .snp file, then used a program called Adlib Express to batch convert the .snp files to pdf to another directory on my network....

http://www.adlibsys.com/
Too expensive for me.
:(
 

Users who are viewing this thread

Back
Top Bottom