Solved

How auto export and how auto print - no viewing?

Posted on 2006-06-18
18
2,741 Views
Last Modified: 2008-01-09
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
Comment
Question by:EYoung
  • 11
  • 6
18 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 16930682
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
 
LVL 7

Author Comment

by:EYoung
ID: 16930724
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
 
LVL 7

Author Comment

by:EYoung
ID: 16930728
Instead of Word, how do I set the format type to Adobe Acrobat?
0
 
LVL 7

Author Comment

by:EYoung
ID: 16930773
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
 
LVL 7

Author Comment

by:EYoung
ID: 16930935
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
 
LVL 100

Accepted Solution

by:
mlmcc earned 50 total points
ID: 16930973
Try this


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

        crRpt.Export False

mlmcc
0
 
LVL 7

Author Comment

by:EYoung
ID: 16931041
Am trying.  Will get back to you...
0
 
LVL 7

Author Comment

by:EYoung
ID: 16931045
Can you supply the code for "MS_OUTLOOK_running"?  Thanks
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 16931099
Maybe.  I'll try to find it.

mlmcc
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 100

Expert Comment

by:mlmcc
ID: 16931137
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
 
LVL 7

Author Comment

by:EYoung
ID: 16931190
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
 
LVL 7

Author Comment

by:EYoung
ID: 16931273
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 16931297
Glad you figured it out.  We still use CR8 that doesn't have PDF as an export option.

mlmcc
0
 
LVL 7

Author Comment

by:EYoung
ID: 16931318
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
 
LVL 7

Expert Comment

by:janmarini
ID: 16931807

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

Author Comment

by:EYoung
ID: 16938526
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 16938826
Glad i could help

mlmcc
0
 
LVL 7

Author Comment

by:EYoung
ID: 16939081
dlls drive me crazy
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

9 Experts available now in Live!

Get 1:1 Help Now