Solved

Disable Cancel or Catch it in system dialogue

Posted on 2002-06-05
9
287 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

785 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