how to close an open pdf file

Posted on 2006-10-23
Medium Priority
Last Modified: 2013-12-25
hi experts,

i created a fax printing module and its working fine except that when it comes to execute the actual code that sends out the file to the fax printer, the code automatically opens up that file.

its not that big a problem but i was thinking that it would be nice if i can close that file before the program ends.  i tried using getobject then closing it but its not working.

would appreciate any ideas.


Question by:wala_lang
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17793597
can you show the code to print and the getobject part

Author Comment

ID: 17801076
Hi Angel,

Sorry if my post is a bit long......reckon it might take you a while to go over them.....anyway, here it goes and thanks for your time by the way.

I was just testing it and I noticed something.  I'm not sure if this is how the fax module is supposed to work but I noticed that whenever it execute the following code:

JobIDObj = FaxDocumentObj.ConnectedSubmit(FaxServerObj)

it opens up the attachment and it will not close it afterward.

Coz the whole process of my system is I automatically export a crystal report to a pdf and attach the file to the fax document object and then sends off the fax using the default cover page.  Everything is running fine except that its so annoying that the attached file is left open.

I commented out the getobject part because I am passing the exported filename as the parameter and I am getting an object required error on that bit.  Maybe because its not the exported file that is open but a copy of that file that the fax object is using whenever it executes the connectedsubmit event.  I checked the name of the file that is left open and its different from the filename that I used when I exported the report.  And I also noticed that the fax module is generating a random filename that it uses everytime it executes the event connectedsubmit.

The complete code is shown below:

Global gConnection As ADODB.Connection, gStrSaPass As String, gConnection2 As ADODB.Connection Global gstrJobexFile As String, gstrJobexInvFile As String
Global gstrDataSource As String, gStrSaID As String, gstrDBName2 As String
Global gstrJobexTool As String, gstrJobexTool2 As String
Public gcrxCRApp As New CRAXDRT.Application, mstrReportName As String, bolLoop As Boolean
Public PDFApp As Object

Sub Main()
    printForm (Command)
End Sub

Public Function printForm(strParameter As String)
    Dim crParamDefs As CRAXDRT.ParameterFieldDefinitions, rsReportFile As ADODB.Recordset
    Dim crxConnectionInfo As CRAXDRT.ConnectionProperties, strMessage As String
    Dim strUserMessage As String
    Dim fsoFileExists As FileSystemObject, bolRunReport As Boolean, sItems
    Dim rsReportFile2 As ADODB.Recordset
    Dim rsReportFile3 As ADODB.Recordset, strRepID As String
    Dim sReportFile4 As ADODB.Recordset, sReportFile5 As ADODB.Recordset

    sItems = Split(strParameter, ",")
    Set rsReportFile =
          gConnection.Execute("SELECT * from [Single Reports] where repID = '" + sItems(1) + "'")
    Set fsoFileExists = New FileSystemObject    
    If Not rsReportFile.EOF Then
        If fsoFileExists.FileExists(rsReportFile!repname) Then
            mstrReportName = rsReportFile!repname
            Set crxCRRept = Nothing
            Set crxCRRept = gcrxCRApp.OpenReport(mstrReportName, crOpenReportByTempCopy)
            Set crxConnectionInfo = crxCRRept.Database.Tables(1).ConnectionProperties
            crxConnectionInfo.Item("Data Source") = gstrDataSource
            crxConnectionInfo.Item("User ID") = gStrSaID
            crxConnectionInfo.Item("Password") = gStrSaPass
            crxConnectionInfo.Item("Initial Catalog") = gstrDBName2
            crxCRRept.ExportOptions.DestinationType = crEDTDiskFile
            strOutputFile = App.Path & Format(Now, "ddmmyyyy") & Format(Time(), "hhmmss") & ".pdf"
            crxCRRept.ExportOptions.DiskFileName = strOutputFile
            crxCRRept.ExportOptions.FormatType = crEFTPortableDocFormat
            crxCRRept.ParameterFields.Item(1).AddCurrentValue (sItems(0))
            crxCRRept.Export False
            SendFax strOutputFile, sItems(2), sItems(3), sItems(4)
            MsgBox "Report file " + rsReportFile!repname + " is not existing.", vbCritical, "System Message"
        End If
    End If
    Set rsReportFile = Nothing
    Set fsoFileExists = Nothing
    Set crxCRRept = Nothing
    Set gcrxCRApp = Nothing
    If gConnection.State = adStateOpen Then
    End If
    Exit Function

        MsgBox "Error Retrieving the Report Data. " & Err.Description, vbCritical, "System Error"
End Function

Private Sub SendFax(ByVal strFile As String, ByVal strFax As String,ByVal strRecipient As String,
                               ByVal strSubject As String)
Dim FaxDocumentObj As New FAXCOMEXLib.FaxDocument
Dim FaxServerObj As New FAXCOMEXLib.FaxServer
Dim JobIDObj As Variant

'Error handling.
On Error GoTo Error_Handler

'Connect to the fax server.
FaxServerObj.Connect "\\s-syd-25"

'Set the fax body.
FaxDocumentObj.Body = strFile

'Name the document.
FaxDocumentObj.DocumentName = "Fax Message from Service Center using Crystal"

'Set the fax priority.
FaxDocumentObj.Priority = fptHIGH

'Add the recipient with the fax number
FaxDocumentObj.Recipients.Add strFax, strRecipient

'Choose to attach the fax to the fax receipt.
FaxDocumentObj.AttachFaxToReceipt = True

'Set the cover page type and the path of the cover page.
FaxDocumentObj.CoverPageType = fcptSERVER
FaxDocumentObj.CoverPage = "CDM Cover Page"
FaxDocumentObj.Subject = strSubject

'Set the sender properties.
FaxDocumentObj.Sender.Company = "CDM Pty Ltd."
FaxDocumentObj.Sender.Name = "Ann Ramos"
FaxDocumentObj.Sender.OfficePhone = "02856754646"
FaxDocumentObj.Sender.FaxNumber = "028465646"

'FaxDocumentObj.CoverPage = False
JobIDObj = FaxDocumentObj.ConnectedSubmit(FaxServerObj)

'Set PDFApp = GetObject(strFile)
'With PDFApp
'    .Close
'End With
'Set PDFApp = Nothing

Set FaxDocumentObj = Nothing
Set FaxServerObj = Nothing

Exit Sub

    'Implement error handling at the end of your subroutine. This implementation is for demonstration purposes
    MsgBox "Error number: " & Err.Number & ", " & Err.Description & ". Please contact service desk application support."
End Sub


Expert Comment

ID: 17801261
Hello Sir,

  Check the following site if it can help you.


withr regards,

Author Comment

ID: 17824332
figured it out.....changed the output to doc.  when fax object sends it to the fax printer, it automatically closes it after.  i decided to use doc instead.

thanks for the time guys.

Accepted Solution

CetusMOD earned 0 total points
ID: 18059472
Closed, 30 points refunded.
Community Support Moderator

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question