Solved

Common Dialog ShowPrinter Cancel

Posted on 2000-04-27
8
1,317 Views
Last Modified: 2012-05-04
I'm having trouble canceling from the show printer screen.

Here's what I'm using

CommonDialog1.ShowPrinter
RichTextBox1.SelPrint CommonDialog1.hDC
0
Comment
Question by:aomega
  • 3
  • 3
  • 2
8 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2755382
Use:

CommonDialog1.CancelError = True
On Error GoTo ErrHandler
CommonDialog1.ShowPrinter
'...
Exit Sub

ErrHandler:
'User pressed Cancel
End Sub
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2755393
What exactly is the problem ?

To detect cancel you can set the CancelError property to true and then put an error trap around your code, ie

On Error Goto Cancel

CommonDialog1.ShowPrinter

RichTextBox1.SelPrint CommonDialog1.hDC

Exit Sub

Cancel:

'Dont print anything

End Sub
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2756055
On Error Resume Next
Form1.ShowPrinter
If (Err.Number <> cdlCancel) Then
    '...do something...
End IF
On Error Goto 0
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 32

Expert Comment

by:Erick37
ID: 2756754
GivenRandy, if you are going to lock a question with an answer, please be sure it at least works.  Paul and I have both given examples of how to use the CnacelError property in conjunction with On Error to achieve this.

Form1.ShowPrinter?
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2756848
You're right.  I usually do test code segments before posting, but not this time -- haste makes waste.

Erick's answer is very similar to mine, although slightly different (mine avoids clumsy indirect "goto" statements).  I'll withdraw the lock and let the poster decide.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2756919
I would caution against using "On Error Resume Next" unless you are absolutely sure other runtime errors can safely be ignored in the code.

Error handlers are typically / usually implemented as "indirect" GoTo's.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2757769
We are both concerned with the same problem with VB (other languages handle it differently -- some better, some worse).  Like you said, if you don't have your functions adequately protected, it might be better to trap by doing the "indirect" method.

What happens is that an error condition that occurs will trigger this and go to whereever it is indicated.  In Erick's recommendation, it would bail to his GoTo point.  This is a good approach if you're not sure about the other code or how your own code functions at a deeper level.  However, if your code is more robust, I prefer my approach -- keep it close to the chest.
0
 
LVL 3

Accepted Solution

by:
paulstamp earned 25 total points
ID: 2889954
Set the CancelError property to true and then put an error trap around your code, ie

On Error Goto Cancel

CommonDialog1.ShowPrinter

RichTextBox1.SelPrint CommonDialog1.hDC

Exit Sub

Cancel:

'Dont print anything

End Sub


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question