Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Printer Dialog and Parameters

Avatar of jmitchell13760
jmitchell13760 asked on
Visual Basic Classic
8 Comments1 Solution1794 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSoundFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answers