Solved

Trigger for Cancel button in CommonDialog

Posted on 1998-12-22
3
241 Views
Last Modified: 2008-02-26
VB5:
In the Programmers Guide I find this example for the CommonDialog control, when opening a file from the Open dialog:

Private Sub mnuFileOpen_Click()
  ' CancelError is True.
  On Error Goto ErrHandler
  ...

ErrHandler:
  ' User pressed Cancel button.
  Exit Sub
End Sub

However, this doesn't work for me. Here's my code:

On Error GoTo Hell
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
sFile = CommonDialog1.filename
...

Hell:
  Exit Sub

The code stops, as usual, after the .ShowOpen call, but then it _continues_ even if I pressed the Cancel button. Is it any other way to know when the user pressed the button?
0
Comment
Question by:liljegren
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
spenner earned 100 total points
ID: 1452022
Two methods - one is to use the commondialog box made by the ccrp
http://www.mvps.org/ccrp/

The other is to insert this line
On Error GoTo Hell
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.CancelError = True   ' **** insert this line ***
CommonDialog1.ShowOpen
sFile = CommonDialog1.filename
.

Hell:
  Exit Sub
0
 

Author Comment

by:liljegren
ID: 1452023
Thanks. Can you tell me, what's the difference with the ccrp common dialog box?
0
 
LVL 2

Expert Comment

by:spenner
ID: 1452024
The ccrp common dialog box adds several extended features.
-You can add controls to the dialog box (ie. a picture box for a preview)
-It returns whether or not the cancel button was pressed
 (if ccrpcd.DialogCanceled = True Then exit sub)
-You can change the captions on the OK and Cancel Buttons
-It returns an event for when someone changes directories
-It is positionable on the screen (x,y coordinates)
-It comes in an ocx of about 130k, so if you only need the common dialog box, you don't need to include all 500k of comdlg32.ocx, but just the ccrp ocx.
-There's a bunch of other stuff too, but I can't remember it all.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now