Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Common Dialog ShowPrinter Cancel

Posted on 2000-04-27
8
Medium Priority
?
1,380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

715 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