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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog Cancel Error

Status
Not open for further replies.

Vec

IS-IT--Management
Jan 29, 2002
418
0
0
US
How do I stop the cancel error (76) caused when a user cancels a common dialog box. Here is my code so far:

With CommonDialog1
.DialogTitle = "Open File"
.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
.Filter = "Text Files(*.txt)|*.txt"
.ShowOpen
End With

I am not sure how to use .CancelError (If that is what is applicable here) "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
-- Rich Cook.

teklogo.gif

 
After the .showopen do this
If Len(.FileName) = 0 Then
Exit Sub
End If
 
The other alternative is:

Code:
With CommonDialog1
   .CancelError = True
   On Error GoTo EndFileOpen
   .DialogTitle = "Open File"
   .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
   .Filter = "Text Files(*.txt)|*.txt"
   .ShowOpen
End With

EndFileOpen:

   ' Continue code here.

Hope this helps
 
Add these code before statement: .ShowOpen
'---------------------
'Code here
......
On Error Goto ErrorHandle
CommonDialog1.ShowOpen
......
ErrorHandle:
'Please code here if you want
End Sub/Function

'End code
'----------------------

Good luck and have fun
KieuTV




 
OK, question 2:
How do you look at a list box and determin if it is empty?

Pseudo:

If List1.List is Empty Then
MsgBox "List Empty!"
End If "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
-- Rich Cook.

teklogo.gif

 
And also how do you count the number of items in a list box and then display how many items are in it in a MsgBox so that a MsgBox pops open and says something like "200 Items in List Box" "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
-- Rich Cook.

teklogo.gif

 

Vec, a lot of question in one thread! Should be more than one but here goes...

With OzWolf's you could also test for the error if you wanted to...
[tt]
If Err.Number = 32755 Then Exit Sub 'User Pressed Cancel
[/tt]

Now to answer Q2 and Q3 you can use the ListCount property to test to see if there are any items in the listbox or not.
[tt]
MsgBox "There Are " & List1.ListCount & " Items"
[/tt]

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top