Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report Configure Printer Button

Status
Not open for further replies.

noahethan

Programmer
Jul 8, 2006
9
US
In Crystal Viewer:

Does anyone know how to create a command button that will allow you to select a different printer then the default printer, like a print setup button.

Currently I am using the MCDC with the following code in the printclick event

UseDefault = .F.

Thisform.Olecontrol1.CancelError = .T.
Thisform.Olecontrol1.ShowPrinter


But this is prompting to select then showing the crystal print window.
 

Hi Noahethan,

Off the top of my head, you need something like this (in the PrintClick event):

Code:
Usedefault = .F.  && overrides built-in behaviour
lcPrinter = GETPRINTER() &&VRP printer dialogue
IF empty(lcPrinter)
  * User cancelled printer dialogue
  RETURN
ELSE
  oRep.SetPrinter(lcPrinter)
  oRep.Printout(.F.)  && or pass .T. to display the
                      && "number of copies" dialogue
ENDIF

oRep is your report object reference.

I haven't tested the above, but it should give you a start.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike, I was playing around with the same thing but all it does is prompt me and then nothing else.
 
Yeah, my code was a little different then your but neither print, any ideas ?
 
I pretty much replaced mine with yours, lol.



*** ActiveX Control Event ***
LPARAMETERS usedefault

Usedefault = .F. && overrides built-in behaviour
lcPrinter = GETPRINTER() &&VRP printer dialogue
IF empty(lcPrinter)
* User cancelled printer dialogue
RETURN
ELSE
Thisform.OleCrView.SetPrinter(lcPrinter)
Thisform.OleCrView.Printout(.F.)
Thisform.OleCrView.PrintReport(lcPrinter)
&& or pass .T. to display the
ENDIF





Mine was like this

Local lcNewPrn, lcCurrPrn, lnRet

lcCurrPrn = Upper(Set("Printer", 2))

lcNewPrn = Upper(Alltrim(Getprinter()))

If Empty(lcNewPrn)
Return
Endif

If Empty(lcCurrPrn) .Or. !(lcCurrPrn == lcNewPrn)
*!* lnRet = SetDefaultPrinter(@lcNewPrn)
SET PRINTER TO NAME (lcNewPrn)
If lnRet = .T.
= Messagebox([Cannot set ] + lcNewPrn + ;
[ as default printer!], ;
16, "Set New Default Printer")
Endif
Endif (Empty(lcCurrPrn) .Or. !(lcCurrPrn == lcNewPrn))


 
Why not use the printer setup dialog from Crystal Reports rather than the one in VFP? Try this:

oRep.PrinterSetup()

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
I dont get that option with the ActiveX componet I am using. I am using the CrystalReports10.ActiveXReportViewer.1
 

Noahethan,

The code I posted works for me, as does Craig's. I am also using the ActiveX report viewer. I don't have CR 10, but it works in 8.x, 9 and 11, so it's unlikely that 10 will be different.

Are you sure you have a valid report object? Can you see the report in the viewer?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Yeah, the report works great, filters by passing SQL code, exports fine, just cant get the report to print to anything besides the default printer.
 
The viewer has absolutely no options for printing at all. It has a button that calls the print method of the report object. It's also the report object that has the printersetup. So, stop looking at the viewer, and start looking at the report object.

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
The only activex controls I have for crystal are

1) Crystal ActiveX Report Viewer Control 10.0
2) Crystal Report Control 10.0



What name am I looking for ?
 

Noahethan,

What you are looking for is the Crystal Reports Report Design Component (RDC). You must have that, because you can't do any any of this without it.

Somewhere in your application, you have code something like this:

Code:
oCR = CREATEOBJECT("CrystalRuntime.Application")
...
oRep = oCR.OpenReport("c:\reports\MyReport.RPT")

In this example, oCR is an instance of the Report Design Component, and oRep is a report object. It is these objects that expose most of the properties and methods you are interested in.

These methods include SelectPrinter(), which tells the RDC which printer to use, and Printout(), which actually prints the report. These are both methods of the report object (oRep in my example, above).

The fact that you are trying to call these methods from an event-handler in the ActiveX control is not really relevant. As Craig says, it is the report object you need to focus on.

My advice would be to execute the code shown here from the command window as a first step to understanding how to print a report.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top