Link to home
Start Free TrialLog in
Avatar of EYoung
EYoungFlag for United States of America

asked on

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.
Avatar of Mike McCracken
Mike McCracken

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
Avatar of EYoung

ASKER

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...
Avatar of EYoung

ASKER

Instead of Word, how do I set the format type to Adobe Acrobat?
Avatar of EYoung

ASKER

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
Avatar of EYoung

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EYoung

ASKER

Am trying.  Will get back to you...
Avatar of EYoung

ASKER

Can you supply the code for "MS_OUTLOOK_running"?  Thanks
Maybe.  I'll try to find it.

mlmcc
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
Avatar of EYoung

ASKER

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.
Avatar of EYoung

ASKER

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
Glad you figured it out.  We still use CR8 that doesn't have PDF as an export option.

mlmcc
Avatar of EYoung

ASKER

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

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
Avatar of EYoung

ASKER

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...
Glad i could help

mlmcc
Avatar of EYoung

ASKER

dlls drive me crazy