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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Setup Button

Status
Not open for further replies.

rickkcir

Technical User
Jul 31, 2002
35
Does anyone know how to make a button pull up the print setup screen in VB6? To be clear, when I say print setup screen, I mean the screen where you can select your printer and select landscape or portrait.

Thanks.
 
I imagine it's the same as VB5. If so you need to add a Common Dialog control to your form then behind your print button (Command1) paste the code:-

Private Sub Command1_Click()
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
CommonDialog1.ShowPrinter

Exit Sub
ErrHandler:
End Sub

This is only the bare essentials and won't actually print anything.

Big Al
 
Thank you very much...I had actually figured this much out just now...but was very confused when I couldn't get anything to print out.

So, how do I make this actually print something?
 
That depends on what you need to print.

Is it an image, a file, a form or what?
 
It is a Crystal Report inside of a form. Basically, I am using the form to display the Crystal Viewer which has a Crystal report in it.
 
Anyone have any information on how you get Big Al's solution above to actually print something.

Thank you in advance for following up.
 
Hi rickkcir,

are you using crViewer91? if yes then set the enablePrintButton property to true and you will get a button for printing. No need to add extra code.

Regards,
nicsin
 
Thank nicsin,

I'm not sure if I'm using crViewer91. I'm using the crViewer activeX form, I'm just not sure the number I guess. But I know what you are saying regarding the enalbePrintButton property, and yes, that does work to print the report.

However, there is no enablePrintSetupButton property, which I need in there to be able to set up a report to print in landscape, and therefore, I need to get this through the common dialog control. It is through the common dialog control that I can't get anything to print.

Now, if you know how to get a print setup button to appear on my crViewer, that would be even better, but it is my understanding that that property does not exist.

Thank you.
 
Hi rickkcir,

I misunderstood your question. I apologise for that! I haven't actually used the common dialogue control for printing but I am sure someone else will answer shortly.

Regards,
nicsin
 
Printing from crystal atually got a lot harder than I expected. I started out using the common dialog but found that it changed the system default printer to the printer you selected and did not want to be changing that. I ended up spending some time searching crystals web site and found a patch you can apply to crystal to use the code below.

I am using vb 6.0 and crystal reports 8.5 developers edition
not sure shich versions the patch applys to but it should say so on thier web site. the patch really only enables you to detect the cancel button being pressed. you could just use crreport.printersetup to show the printer set up box but it does not recognize the cancel button.


i did away with the print button on the viewer and added my own print button on the form with the viewer.

I do a lot of recordset work before displaying report susch as changing the database locations (which was a challenge in itself) but here is a cut down version of what i use.


Private Sub Print_Click()
Dim crreport As New Invoice


' Detects if the cancel button is pressed

If crreport.PrinterSetupEx(Me.hWnd = 0) Then
Exit Sub


End If


' refresh the report
crreport.DiscardSavedData


' Prints the report
crreport.PrintOut (False)


End sub


Hope this helps
 
Thanks a lot AZRobert...this definitely will get me going in the right direction.
 
Does anyone know how to print report to a prn file. The problem is to programmatically set "Print to file" option on a print dialog box and specify the output file.
Thanks for any input.

tnovak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top