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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 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