• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2749
  • Last Modified:

How auto export and how auto print - no viewing?

I have written many VB6 applications that use Crystal Reports to display reports on the screen and allow the users to do whatever they want with the reports, i.e. view, print, export, etc.

Now the users of the applications are asking for two new features.  To automatically export the report to an Adobe Acrobat file or to automatically print the report to the default printer.  In either case the user does not want to have the report shown on the screen.  Just do the export or do the print, no viewing on the screen.

So I have created in VB6 some options that the users can click to select their choice, i.e. Send (export to Adobe, no viewing on screen), View (display report on screen) or Print (print to the printer, no viewing on screen.)

The Viewing code works just fine.  However, I can't figure out how to "automatically" export to Adobe Acrobat or "automatically" print to the printer without first showing the CRViewer9 control on the screen.

Specifically I want to do the following:

Send - Not show the report in CRViewer, just export automatically to an Adobe Acrobat file in a predefined folder, i.e. "C:\Temp\" without any prompts.

View - Works just fine.

Print - Not show the report in CRViewer, just print automatically to the default printer without any prompts.

Below is the code I have been using in the VB6 form that shows the report:

*******************************************************
Option Explicit

Dim Report As dsrSWR

Private Sub CRViewer92_PrintButtonClicked(UseDefault As Boolean)
    UseDefault = False
    Report.PrinterSetup (hWnd)
    Report.PaperOrientation = crPortrait
    'Report.PaperOrientation = crLandscape
    On Error GoTo Cancel:
    Report.PrintOut True

Cancel:
    Exit Sub
End Sub

Private Sub Form_Activate()
    Set Report = New dsrSWR

    Report.EnableParameterPrompting = False

    Report.ParameterFields(1).AddCurrentValue mSWR_Date
    Report.ParameterFields(2).AddCurrentValue mEmployee_mKey
    Report.ParameterFields(3).AddCurrentValue mFilled_or_Blank_Parm
    Report.ParameterFields(4).AddCurrentValue mQuantity_Parm
    Report.ParameterFields(5).AddCurrentValue mDefault_User_Name

    Select Case mSend_View_or_Print_Parm
        Case "S"
            Unload Me
        Case "V"
            Screen.MousePointer = vbHourglass
            CRViewer92.ReportSource = Report
            CRViewer92.DisplayTabs = False
            CRViewer92.DisplayToolbar = True
            CRViewer92.EnableGroupTree = False
            CRViewer92.EnableExportButton = True
            CRViewer92.ViewReport
            CRViewer92.Zoom (100)
            Screen.MousePointer = vbDefault
        Case "P"
            Screen.MousePointer = vbHourglass
            CRViewer92.ReportSource = Report
            CRViewer92.DisplayTabs = False
            CRViewer92.DisplayToolbar = True
            CRViewer92.EnableGroupTree = False
            CRViewer92.EnableExportButton = True
            CRViewer92.ViewReport
            CRViewer92_PrintButtonClicked (True)
            CRViewer92.Zoom (100)
            Screen.MousePointer = vbDefault
    End Select
End Sub

Private Sub Form_Resize()
    CRViewer92.Top = 0
    CRViewer92.Left = 0
    CRViewer92.Height = ScaleHeight
    CRViewer92.Width = ScaleWidth
End Sub
*******************************************************

Thanks for the help.
0
EYoung
Asked:
EYoung
  • 11
  • 6
1 Solution
 
mlmccCommented:
Try code like this to print

    Private crApp As CRAXDRT.Application
    Private crRpt As CRAXDRT.Report

'
'   Check if report is already in use
'
        If IsObject(crRpt) Then
           Set crRpt = Nothing
        End If

'
'   Open report
'
        Set crApp = New CRAXDRT.Application

        Set crRpt = crApp.OpenReport(txtReportName, 1)
        crRpt.RecordSelectionFormula = txtSelectClause

'
'   Set flags for CRViewer
'
        crRpt.MorePrintEngineErrorMessages = False
        crRpt.EnableParameterPrompting = False
        crRpt.DiscardSavedData

        crRpt.DisplayProgressDialog = False
        crRpt.PrintOut


Exporting to Word document and mailing it

    Private crApp As CRAXDRT.Application
    Private crRpt As CRAXDRT.Report

'
'   Check if report is already in use
'
    If IsObject(crRpt) Then
       Set crRpt = Nothing
    End If

'
'   Open report
'
    Set crApp = New CRAXDRT.Application

    Set crRpt = crApp.OpenReport(txtReportName, 1)
    crRpt.RecordSelectionFormula = txtSelectClause
   
    crRpt.MorePrintEngineErrorMessages = False
    crRpt.EnableParameterPrompting = False
    crRpt.DisplayProgressDialog = False
    crRpt.DiscardSavedData

'
'   Set export options
'
    If MS_OUTLOOK_running Then
        crRpt.ExportOptions.DestinationType = crEDTEMailMAPI
        crRpt.ExportOptions.MailToList = txtMailAddress
        crRpt.ExportOptions.MailSubject = txtMailSubject
        crRpt.ExportOptions.MailMessage = txtMailMessage
        crRpt.ExportOptions.FormatType = crEFTWordForWindows

        crRpt.Export False

mlmcc
0
 
EYoungAuthor Commented:
Thanks mlmcc.  I'll try it and get back to you.  Glad to see I am not the only one working today.  Good to hear from you...
0
 
EYoungAuthor Commented:
Instead of Word, how do I set the format type to Adobe Acrobat?
0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
EYoungAuthor Commented:
mlmcc,

Here is the code for just printing.  How do I not show the dialog box that asks for the print range and number of copies to print?  (Everything with the print work fine.)

Private Sub srPrint_SWR()
'
'   Open report and pass parameters
'
    Set Report = New dsrSWR

    Report.EnableParameterPrompting = False

    Report.ParameterFields(1).AddCurrentValue mSWR_Date
    Report.ParameterFields(2).AddCurrentValue mEmployee_mKey
    Report.ParameterFields(3).AddCurrentValue mFilled_or_Blank_Parm
    Report.ParameterFields(4).AddCurrentValue mQuantity_Parm
    Report.ParameterFields(5).AddCurrentValue mDefault_User_Name
'
'   Set flags for Report
'
    Report.MorePrintEngineErrorMessages = False
    Report.DisplayProgressDialog = False
'
'   Print the report
'
    Report.PrintOut
End Sub
0
 
EYoungAuthor Commented:
mlmcc,

I got the printing to work without prompting from a dialog box.  The "False" option at the end did the trick.  See below:

Private Sub srPrint_SWR()
'
'   Open report and pass parameters
'
    Set Report = New dsrSWR

    Report.EnableParameterPrompting = False

    Report.ParameterFields(1).AddCurrentValue mSWR_Date
    Report.ParameterFields(2).AddCurrentValue mEmployee_mKey
    Report.ParameterFields(3).AddCurrentValue mFilled_or_Blank_Parm
    Report.ParameterFields(4).AddCurrentValue mQuantity_Parm
    Report.ParameterFields(5).AddCurrentValue mDefault_User_Name
'
'   Set flags for Report
'
    Report.MorePrintEngineErrorMessages = False
    Report.DisplayProgressDialog = False
'
'   Print the report
'
    Report.PrintOut False, mQuantity_Parm
End Sub


Now all I have to do is the exporting to Adobe Acrobat...
0
 
mlmccCommented:
Try this


        crRpt.ExportOptions.DestinationType = crEDTDiskFile
        crRpt.ExportOptions.FormatType = crPortableDocumentFile

        crRpt.Export False

mlmcc
0
 
EYoungAuthor Commented:
Am trying.  Will get back to you...
0
 
EYoungAuthor Commented:
Can you supply the code for "MS_OUTLOOK_running"?  Thanks
0
 
mlmccCommented:
Maybe.  I'll try to find it.

mlmcc
0
 
mlmccCommented:
I apparently don't have it here.  I'll check at work.  It may have been a call to one of the dlls we included.

mlmcc
0
 
EYoungAuthor Commented:
I am getting a Run-time error when I try the export to Adobe.  Message on screen is:

Run-time error '-214...
Error in File ??:
Missing or out-of-date export DLL.

Do you know which dll is needed?  Thanks for the help.
0
 
EYoungAuthor Commented:
Its the U2FCR.dll and I am working with the techs on it now.  Will get back to you.  See last posting in this link:

http://p2p.wrox.com/topic.asp?TOPIC_ID=7334
0
 
mlmccCommented:
Glad you figured it out.  We still use CR8 that doesn't have PDF as an export option.

mlmcc
0
 
EYoungAuthor Commented:
I really appreciate your help.  You have provided much needed help over the years and I am grateful for all of it.  I need to leave now but will be back first thing in the morning.  (I am in California, US).  Regards...
0
 
janmariniCommented:

Here is some info on exporting to PDF using CR 8.5 - not sure if it applies well for CR 9.  Anyway, I hope it might give you some ideas to get started.  I automatically export to PDF with no problem using CR 9, but I'm using VS.Net (will send sample code if you'd like) - it's been years since I've used VB 6 and it's just not coming back to me (yikes - in the last 4 years went from VS 6 to .Net 2002, 2003, 2005 - CR 8.5, 9, 10, XI and each of the .Net versions in between - too much).

Please see:  http://support.businessobjects.com/library/kbase/articles/c2010117.asp

Jan
0
 
EYoungAuthor Commented:
Thanks for the help to both of you.  I am still getting an error message "Failed to export report" but I will do some research and possibly post another question.

mlmcc - if you find the routine to check on whether or not outlook is running, pleaes post.

Thanks again...
0
 
mlmccCommented:
Glad i could help

mlmcc
0
 
EYoungAuthor Commented:
dlls drive me crazy
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 11
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now