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!

CommonDialog ShowPrinter not displaying reliably

Status
Not open for further replies.

jbradley

Programmer
Sep 7, 2001
248
0
0
US
I'm using VB6 SP5 and the Crystal Reports OCX to produce some output from a recordset. If the user chooses to send the output directly to the printer rather than display it then I use the CommonDialog ShowPrinter method to pop up a printer dialog box before sending the output to the printer. My problem is that the printer dialog is not always displayed, either running from the IDE or running the compiled application and I can't figure out why. Sometimes closing the program then launching it again fixes the problem temporarily, sometimes restarting the PC cures it and sometimes nothing seems to work. Here is the pertinent code, which resides in a Sub in a module that I'm calling from the Click event of a command button on the main form:
Code:
With frmMain.CrystalReport1
    .SetTablePrivateData 0, 3, rs
    .ReportFileName = ReportName
    .DiscardSavedData = True
    .WindowTitle = WindowTitle
    .WindowState = crptNormal
    If HardCopy = False Then
        .Destination = 0 ' To Screen
    Else
        .Destination = 1 ' To Printer
            Select Case Right$(ReportName, Len(ReportName) - InStrRev(ReportName, "\"))
                Case "EpayFullBatch.rpt", "CollectionLetter.rpt"
                    MsgBox "Choose plain-paper printer or load plain paper", vbExclamation
                Case "EpayChecks.rpt"
                    MsgBox "Choose check printer or load check paper", vbCritical
            End Select
        frmMain.Dialog1.ShowPrinter
    End If
    .Action = 1
End With
Any suggestions how to resolve this would be greatly appreciated.
 
Not sure if this will help, but...

I had a similar problem with unexpected printer problems. I kept getting the error

"Run time error '486':
Can't Print form image to this type of printer"

This was fixed by including "Printer.EndDoc" after the form was printed (the error occurred the second time I tried to print the form)
you don't mention any errors - have you supressed them through OnError Resume Next ?

Hope it's not been a total waste of my time typing this out... ;-)

Steve

P.S. If it works, credit should go to vb5prgrmr for giving me this tip/solution


 
I may not have been clear on what the problem is. When I step through the code, the line:
Code:
frmMain.Dialog1.ShowPrinter
is executed but the printer dialog is not actually displayed although if I watch the screen very carefully I can convince myself that there was a brief flash. It's as if the dialog is displayed invisibly and an invisible user clicks the OK button on it. The following lines then execute and the output is sent to the current default printer without pause or opportunity to cancel or choose a different printer.
 
Hi

Wrong track.. lets try annother...

Does anyone know if the common dialog is automaticaly Modal? I honestly cannot remember... try adding VBModal after the .showprinter

Steve
 
Which O/S are you running on? If W9x/ME and resources are low then dialogs don't display. I've seen certain video drivers temporarilly drain resources and cause this type of problem intermittently.

Paul Bent
Northwind IT Systems
 
I'm running on NT Workstation 4.0.

I moved the code to display the printer dialog to the calling procedure on the main form and it works every time there. I had to add three instances, one for each call to the output procedure. Unfortuately, now clicking the Cancel button on the print dialog now drops me to the error handler in the cmdPrint_Click procedure and cancels all the printing, not just the particular instance.
 
As a further update to this problem, I had been using the same Common Dialog control to open a file for input, then later to show a printer dialog. I discovered that if I opened an input file anywhere other than in the InitDir of the ShowOpen Dialog, then later when I wanted to display a printer dialog it wouldn't. I ended up adding a second control to the form for use exclusively as a printer dialog.

If anyone can provied an insight concerning this odd behavior it would be appreciated. Otherwise, thanks for your suggestions.
 
I think I may have a sloution for you, this is what worked for me under similar but different circumstances.

The Crystal OCX is persnickety. I found that unless I very deliberately destroyed the object (set object = nothing) when I was done with it, the next time I tried to use it I got similar results to what you are seeing, namely the box appearing in a quick flash and disappearing.

The problem is an error occurring in the OCX which causes it to abend, but the crystal OCX can't communicate this to the VB IDE. So it fails and closes but your program continues as though everything is fine. Hard to locate.

You can try using the Action method instead of the PrintReport method, which may at least provide an error message indicating what went wrong when the OCX goes bad. But try destroying the Crystal OCX and then re-creating it every time you need it, that may make a lot of your troubles go away.

Best of luck!

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top