Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Look In and Cancel on Common Dialog

Status
Not open for further replies.

DougAtAvalon

Programmer
Jan 29, 2001
99
US
On the Click Event of a button, My code is:

--------------
With Brows_btn3
.Filter = "MS Word Files (*.doc)| *.doc| All Files (*.*)| *.*"
.ShowOpen
Me.control.SetFocus
Me.control.Text = .Filename
--------------

Is there a way to
1. set the "lookin" on the dialog box
2. catch the cancel button or incorrect close (not clicking OK)

thanx,
-Doug


 
When you say "lookin", do you mean the directory that the dialog box opens to?
If you do then this should work
.InitDir = "C:\My Folder"

To catch the Cancel button try this
' Exit if user presses Cancel.
If .CancelError Then
Exit Function
End If

Hope this helps
 
Now myclick event reads:

*********************
With Brows_btn3
.Filter = "MS Word Files (*.doc)| *.doc| All Files (*.*)| *.*"
.InitDir = "path"
.ShowOpen
' Exit if user presses Cancel.
If .CancelError Then Exit Sub
Me.control.SetFocus
Me.control.Text = .Filename
End With
******************
the cancel event doesn't work
Any more ideas?
-Doug
 
I think you need to put the .CancelError before the .ShowOpen, that way the property for the dialog box is set before it is actually open.
Although I'm not positive about this...
 
Hi Doug, try this sample of code to trap the cancel button. All you have to do, is make sure that you set the property CancelError to Yes in the properties of the CommonDialog Control.

Private Sub cmdBrowse_Click()
On Error GoTo err_cdlgOpen

- write your code here -

OpenExit:
Exit Sub

err_cdlgOpen:
If Err.Number = 32755 Then
Resume OpenExit
Else
MsgBox Err.Number & " " & Err.Description
Resume OpenExit
End If
End Sub

Hope this can help you.

Yc
 
If you're talking about the cancel button on the common dialog, set the path to "" and check the value of the path. If it's "" then the cancel button must have been pressed.

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top