Solved

Printer Dialog and Parameters

Posted on 2004-03-30
8
1,646 Views
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.  

Thanks.
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
'Else
    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

CRViewer1.ViewReport

CRRep.DiscardSavedData
CRRep.EnableParameterPrompting = True
'CRRep.VerifyOnEveryPrint = False
CRViewer1.Refresh

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
0
Comment
Question by:jmitchell13760
  • 4
  • 4
8 Comments
 
LVL 28

Accepted Solution

by:
AzraSound earned 500 total points
Comment Utility
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
    CommonDialog1.ShowPrinter
   
    Report.PrintOut False
    Exit Sub
   
Cancel:
    If Err.Number <> cdlCancel Then
        MsgBox Err.Number & " : " & Err.Description, vbExclamation + vbOKOnly, _
            "PrintButtonClicked"
    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.   :-)
0
 

Author Comment

by:jmitchell13760
Comment Utility
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?

Thanks.
Jeff
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
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
    .ShowPrinter
End With
0
 

Author Comment

by:jmitchell13760
Comment Utility
That seemed to resolve my problems.  Thank you very much for your assistance.
0
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.

 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
Glad I could help  :-)
0
 

Author Comment

by:jmitchell13760
Comment Utility
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.
Jeff
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
>>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?
0
 

Author Comment

by:jmitchell13760
Comment Utility
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

763 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

13 Experts available now in Live!

Get 1:1 Help Now