Solved

Disable Cancel or Catch it in system dialogue

Posted on 2002-06-05
9
288 Views
Last Modified: 2010-05-02
Hi,
I am calling the system dialogue to browse, and when I hit cancel i get another system dialogue complaining about long filenames. How can I catch the cancel? Thank you,
d
0
Comment
Question by:dingo11
[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
  • 6
  • 3
9 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7056174
Set .CancelError = True.

You can then trap the error

If Err.Number = cdlCancel Then 'cdlCancel = 32755
  'Handle cancel button
End If
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7056182
Here is an example using the printer dialog but the principle is the same:

Private Sub Command1_Click()
  Dim BeginPage, EndPage, NumCopies, i
  ' Set Cancel to True
  CommonDialog1.CancelError = True
  On Error GoTo ErrHandler
  ' Display the Print dialog box
  CommonDialog1.ShowPrinter
  ' Get user-selected values from the dialog box
  BeginPage = CommonDialog1.FromPage
  EndPage = CommonDialog1.ToPage
  NumCopies = CommonDialog1.Copies
  For i = 1 To NumCopies
    ' Put code here to send data to the printer
  Next i
  Exit Sub
ErrHandler:
  ' User pressed the Cancel button
  Exit Sub
End Sub

0
 

Author Comment

by:dingo11
ID: 7056192
Public Function fBrowseForFolder(hwndOwner As Long, sPrompt As String) As String
On Error GoTo ErrHanndler
' Opens the system dialog for browsing for a folder.
'
    Dim iNull    As Integer
    Dim lpIDList As Long
    Dim lResult  As Long
    Dim sPath    As String
    Dim sPath1   As String
    Dim udtBI    As BrowseInfo
    Dim IDL      As ITEMIDLIST

' Get the ID of the folder to use as the root in the directory box. Change the "CSIDL_"
' constant to any of the defined values as shown in the declarations section of this form.

    sPath1 = fGetSpecialFolder(CSIDL_DESKTOP, IDL)

'Initialize Drag & Drop capabilities in the dialog.
    Call OleInitialize(ByVal 0&)
   
    With udtBI
    '    .pIDLRoot = 0  'Display the entire namespace hierarchy
                        'starting with the desktop folder.
       
        .pIDLRoot = IDL.mkid.cb 'Use the desired starting folder.
   
        .hwndOwner = hwndOwner
        .lpszTitle = lstrcat(sPrompt, "")
   
        'Filter for Folders
        .ulFlags = BIF_RETURNONLYFSDIRS Or BIF_USENEWUI
    End With
   
    lpIDList = SHBrowseForFolder(udtBI)
   
    If lpIDList Then
        sPath = String$(MAX_PATH, 0)
        lResult = SHGetPathFromIDList(lpIDList, sPath)
        Call CoTaskMemFree(lpIDList)
       
        iNull = InStr(sPath, vbNullChar)
        If iNull Then sPath = Left$(sPath, iNull - 1)
    End If
   
    Call OleUninitialize
   
    fBrowseForFolder = sPath
ErrHandler:
    MsgBox err.number
End Function
0
Independent Software Vendors: 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!

 

Author Comment

by:dingo11
ID: 7056199
tim,
I am using the api to call the system dialogue,
d
0
 

Author Comment

by:dingo11
ID: 7056252
Tim,
0 is the result of a cancel. I tried simply existing the function but only ending it stops it.

    If lResult = 0 Then
        End
    Else
        fBrowseForFolder = sPath
    End If
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 65 total points
ID: 7056268
Rather than end the entire application, perhaps use something like this:

   If lResult = 0 Then
       fBrowseForFolder = "NOT FOUND"
   Else
       fBrowseForFolder = sPath
   End If

Then in your calling procedure:

strFolder = fBrowseForFolder (.....)
If strFolder = "NOT FOUND" Then
 'Warn the user and perhaps retry
End If

0
 

Author Comment

by:dingo11
ID: 7056421
Tim,
I can catch it but I cannot seem to get it to exit the function.
d
0
 

Author Comment

by:dingo11
ID: 7056439
tim,
Again I wasn't thinking, there is more going on than the function. THe object that called my function is still processing the info which is an empty string. I'll be back,
d
0
 

Author Comment

by:dingo11
ID: 7056497
Tim,
The calling procedure was obviously the key. Thanks and have a great day programming,
d
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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