[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Printer Dialog and Parameters

Posted on 2004-03-30
Medium Priority
Last Modified: 2007-12-19
I have a VB6 application that calls a Crystal Reports 9.0 viewer dll.  I currently have a form with a viewer control (named crviewer1) which succesfully opens and displays the report.

My users need to be able to print the report, but when doing so they need the print dialog box to appear so they may select a printer, number of copies, page range, etc.  Currently I have most of the functionality I need (see code below) but the user is prompted for the printer selection and the page range in 2 separate dialog boxes.  Also, if they cancel the first dialog, they still receive the second - rather unprofessional.

The larger problem is that many of the reports contain parameters.  When the user clicks print the first time they are prompted for the parameters again (this one confuses the users and they tend to enter the incorrect parameter values - go figure).  According to users, this only happens the first time though, not subsequent times even if the parameters have been changed (and even supposedly if they are looking at a different report, as long as they have not closed the application).

Basically, what is the correct way to print the displayed report (with the current parameters) and give the users full printer dialog control???

I can supply the full project file if it would help.  The entire fnuction of the application is to be a small, compact but full featured crystal report viewer application only.  I have a different screen that displays a list of known reports populated from a DB file.  Once the user selects a report, they can open the viewer form.  

Jeff Mitchell

Code modified frmo Crystal examples:

Dim CRAppl As New CRaxdrt.Application
Dim CRRep As CRaxdrt.Report

Private Sub Form_Load()
  Set CRRep = CRAppl.OpenReport(frm_ReportSelection.Text4.Text)
'The following sets the database location for all tables that are
'used in the report

'Where i is a Long that will be used to increment in a For..Next loop
'depending on the number of tables that exist in the report
Dim i As Long

'From the Report object CrystalReport, we take the current database used
'with the report and assigns it to DbName using the Database property
Set DbName = CRRep.Database

'From the Database object DbName, we take all the tables from the database
'used with the report and assign it to DbTables using the Tables property
Set DbTables = DbName.Tables
Set DbTable = DbTables.Item(1)

frm_ReportSelection.txt_DllName.Text = DbTable.DllName 'gets the DLL name currently in use in the report

'Combo2.AddItem DbTable.LogOnServerName 'gets the Server name currently in use
frm_ReportSelection.txt_ServerName.Text = DbTable.LogOnServerName
'If the original datasource is used, LogOnServer can be used since it just opens up the connection
'and Crystal uses the original connection

If frm_ReportSelection.Check1.Value = 1 Then
    'CrystalApplication.LogOnServer txt_DllName.Text, txt_ServerName.Text, Text1.Text, Text2.Text, Text3.Text
    For i = 1 To DbTables.Count
        'From the DatabaseTables object DbTables, we extract one item (the first table)
        'using the Item property (in CRW, the tables would be listed in order in
        'Database|Set Location)
        Set DbTable = DbTables.Item(i)
        'The SetLogOnInfo method opens up a connection to the database and forces the report
        'to use this connection instead of the one specified in the report. It is then useful
        'if you want to change location of the database for the report. You must set this
        'method for each table. If you want to use the same connection as specified in the report,
        'you can also use the LogOnServer method
        DbTable.SetLogOnInfo frm_ReportSelection.txt_ServerName.Text, , frm_ReportSelection.txt_UserID.Text, frm_ReportSelection.txt_Password.Text
        Next i
End If
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = CRRep
CRViewer1.DisplayTabs = True
CRViewer1.EnableDrillDown = True
CRViewer1.EnableGroupTree = True
CRViewer1.EnableHelpButton = False
CRViewer1.EnablePopupMenu = False
CRViewer1.EnableSelectExpertButton = True
CRViewer1.EnableExportButton = True
CRViewer1.EnableNavigationControls = True
CRViewer1.EnablePrintButton = True
CRViewer1.EnableSearchControl = True
CRViewer1.EnableSearchExpertButton = True
CRViewer1.EnableZoomControl = True
CRViewer1.EnableStopButton = True


CRRep.EnableParameterPrompting = True
'CRRep.VerifyOnEveryPrint = False

Screen.MousePointer = vbDefault
End Sub

Private Sub CRViewer1_PrintButtonClicked(UseDefault As Boolean)

'Create an instance of the Printer Setup dialog box
'Set the handle of the Printer Setup dialog box to the form
CRRep.PrinterSetup frmCrViewer.hWnd

'The 'Print' dialog box will appear by default
'The 'Print' dialog box needs to be displayed if you want the user
'to set start page and stop page, the number of copies, and collate
End Sub

Private Sub Form_Resize()
   CRViewer1.Top = 0
   CRViewer1.Left = 0
   CRViewer1.Height = ScaleHeight
   CRViewer1.Width = ScaleWidth
End Sub
Question by:jmitchell13760
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
  • 4
  • 4
LVL 28

Accepted Solution

AzraSound earned 2000 total points
ID: 10716801
I use CR 8.0 but I always did the print dialog myself using the common dialog control, e.g.,

Private Sub CRViewer1_PrintButtonClicked(UseDefault As Boolean)
    UseDefault = False
    On Error GoTo Cancel
    CommonDialog1.CancelError = True
    CommonDialog1.Flags = cdlPDPrintSetup
    Report.PrintOut False
    Exit Sub
    If Err.Number <> cdlCancel Then
        MsgBox Err.Number & " : " & Err.Description, vbExclamation + vbOKOnly, _
    End If
End Sub

With that being said, it may be as simple as you setting the UseDefault parameter to False (i notice that difference in our two code segments).  I can't honestly say I remember what that parameter was for...its been awhile.   :-)

Author Comment

ID: 10718470
Ok, getting closer, I added a commondialog control and used your code, but I still don't have the option of selecting page ranges to print.

I removed the cdlpdprintsetup flag which gives me a little better print dialog - it includes the number of copies and page range, but the option is just greyed out (and this could be a Crystal problem or something since it looks like I should be able to) - .  I tried playing with cdlpdallpages and such optinos but have not been able to get the pages option enabled - any ideas?

LVL 28

Expert Comment

ID: 10718662
You need to set the Min, Max, FromPage, and ToPage values first, e.g.,

With CommonDialog1
    .Flags = cdlPDPageNums
    .Min = 1
    .Max = 50
    .FromPage = 1
    .ToPage = 50
End With
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 10740750
That seemed to resolve my problems.  Thank you very much for your assistance.
LVL 28

Expert Comment

ID: 10740963
Glad I could help  :-)

Author Comment

ID: 10918432
OK, new problem with this solutino, which appears to be a common one - I am using the commondialog control but it changes the windows default printer to whatever printer was chosen for that print job.  I know I am supposed to be able to change the printerdefault property to false to stop that behavior, but when I do that, it ignores what printer I select and sends the job to the windows default printer.

I could probably get around this (messy though) by using some other code I have to set the window default, ect.

The second problem i have with this solution is that many of my reports have on-demand subreports which I need to be able to print.  The commondialog solution will not allow me to print subreports - when I try, I get the parent report.

So, back to my original question, I either need to be able to supress the parameter prompt when using crystal print code, or print subreports and not change the wnidows default prniter when using the commondialog.

Thanks again for any help.
LVL 28

Expert Comment

ID: 10919306
>>I know I am supposed to be able to change the printerdefault property to false to stop that behavior

This should work.  Are you setting the PrinterDefault property to false BEFORE you call the ShowPrinter method?  If not, you need to be.

>>The commondialog solution will not allow me to print subreports - when I try, I get the parent report

This should have nothing to do with the common dialog control.  Once you have opened the main report and its subreports and told Crystal to process them, they should print out.  Perhaps its an issue with how you are opening your subreports?

Author Comment

ID: 11212469
I never was able to exactly get this working, but found a completely different way of accomplishing the report printer.  Thanks for all your help and time AzraSound.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

649 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