We help IT Professionals succeed at work.

how to close an open pdf file

wala_lang asked
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.


Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

can you show the code to print and the getobject part


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

Hello Sir,

  Check the following site if it can help you.


withr regards,


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.
Closed, 30 points refunded.
Community Support Moderator

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.