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

Cancelled by User Error in Print Dialog Box

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I would like to add a print dialog to my program. Everything seems to be going alright with the exception of the Cancel button. Below is the code I used:

frmMain.dlgCompany.CancelError = True

On Error GoTo ErrorHandler

dlgCompany.Action=5
dlgCompany.PrinterDefault= true
rptEE.CopiesToPrinter=2
rptEE.CopiesToPrinter=dlgCompany.Copies

rptEE.Destination = crptToPrinter
rptEE.Connect = g_sRptConnect
rptEE.Action = 1

Exit Sub

ErrorHandler:
'User presses cancel

Exit Sub


This process is being used to print Checks that were designed using Seagate Crystal Report Designer. However when I press the cancel button, I still get the Cancel by user error. Is there something missing from the code?

Thanks,

Cooleen
 
When I use a common dialogue to select files I use the line:
If dlg.FileName = "" Or Err.Number = cdlCancel Then
to check for cancel being pressed.

Can you use something like this??

Simon [sig][/sig]
 
check for error number 32755 in the error handler whcih is nothing but the error number for the error u mentioned.

so you may insert the following code..

sub yoursub()
on error goto Er_Hnd
''set common dialog to open

exit sub
er_Hnd:
if err.number=32755 then
' take the appropriate action u want to take
end if

end sub [sig][/sig]
 
Thank you very much Simon and Nsvreddy. I tried both these methods several times before. I got them from the Sample programs that come VB, but still I get the same error. I even tested the samples in vb by selecting Cancel and I got the same error. I do not have this problem with the open file dialag, only with the Print dialog.

Cooleen
 

Cooleen,

I just tried this code and it works. Add a new form and place a CommonDialog control on it then insert the following code:

Private Sub Form_Load()
On Error GoTo handle_err
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
Exit Sub
handle_err:
If Err.Number = cdlCancel Then MsgBox "Cancelled"
End Sub
[sig][/sig]
 
It is very simple after all - something we have all been missing .....

On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
If Err.Number = cdlCancel Then
MsgBox [sig][/sig]
 
Something weird happened to the last post, so I will try again..

It is very simple after all - something we have all been missing .....

On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.ShowPrinter
If Err.Number = cdlCancel Then
MsgBox "Cancelled"
Else
MsgBox "Process"
End If

The line 'On Error Resume Next' skips past any popup error dialog and then you can check for cancelled operation.

Simon
[sig][/sig]
 
Is the error comming up in development mode, or exe run time? Maybe you have break on all errors turned on in VB?

Thiught I'd put my 2 cents in. [sig][/sig]
 
Thank you VB400, Simon, and bigfoot. I'll try all of those options. By the way bigfoot, your "2 cents" did cross my mind to check on yesterday, so it's more than just "2 cents".

Thank you,

Cooleen
 
Thanks guys all of your ideas were correct. I ran an exe of my program and I did not get the error. The problem was that I had the break on all errors option selected.

Cooleen
 
Does any one know how to change the print button to say something else
 
I suggest that you start your own thread to ask that question. Read FAQ-2244 for best ways to get a good answer to your question. This thread is 5 years old!

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top