Solved

Trigger for Cancel button in CommonDialog

Posted on 1998-12-22
3
250 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
[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
  • 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

Technology Partners: 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 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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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