Link to home
Start Free TrialLog in
Avatar of liljegren
liljegrenFlag for Sweden

asked on

Trigger for Cancel button in CommonDialog

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?
ASKER CERTIFIED SOLUTION
Avatar of spenner
spenner

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of liljegren

ASKER

Thanks. Can you tell me, what's the difference with the ccrp common dialog box?
Avatar of spenner
spenner

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.