Solved

Common Dialog ShowPrinter Cancel

Posted on 2000-04-27
8
1,353 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
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!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

623 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