Solved

Trigger for Cancel button in CommonDialog

Posted on 1998-12-22
3
244 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

896 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