Solved

Disable Cancel or Catch it in system dialogue

Posted on 2002-06-05
9
286 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
 

Author Comment

by:dingo11
ID: 7056199
tim,
I am using the api to call the system dialogue,
d
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use closed file on desktop in vba 6 67
Excel object stays open 19 71
Updates not working for MS Windows 7 12 153
Added a column screws up code 5 50
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now