Solved

how to close an open pdf file

Posted on 2006-10-23
7
169 Views
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.

regards.

ann
0
Comment
Question by:wala_lang
7 Comments
 
LVL 142

Expert Comment

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

Author Comment

by:wala_lang
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, ",")
    InitializeConnection
    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)
        Else
            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
        gConnection.Close
        End
    End If
    Exit Function

QueryError:
        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

Error_Handler:
    '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

Ann
0
 
LVL 6

Expert Comment

by:saravananvg
ID: 17801261
Hello Sir,

  Check the following site if it can help you.

http://www.print-driver.com/howto/developer/programs/adobe_writer_com_vbnet.htm

withr regards,
padmaja.
0
 

Author Comment

by:wala_lang
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.
0
 

Accepted Solution

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now