how to close an open pdf file

Posted on 2006-10-23
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How does CurrentUser work? 10 42
Copy a row 12 69
Exit a vb6 apps when a calling it apps closes 15 58
How to set the row selection as it was prior leaving the datagrid in vb6 3 55
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 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