Solved

Trigger for Cancel button in CommonDialog

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

776 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