Solved

Disable Cancel or Catch it in system dialogue

Posted on 2002-06-05
9
285 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

747 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

11 Experts available now in Live!

Get 1:1 Help Now