Catch Cancel response in SHBrowseForFolder

B

bhammer

Public Declare Function SHBrowseForFolder Lib "shell32" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

In the calling form, how can I Exit the procedure if the user clicks Cancel
on the Browse for Folder API dialog? I want to Exit to prevent the rest of
the procedure from running.
 
D

Douglas J. Steele

Check whether the function call returned anything, and only continue if it
has.
 
B

bhammer

OK, Doug, I didn't know what question to ask. So, How do I check if the call
function returned anything?
 
D

Douglas J. Steele

Presumably you're assigning the results of the function call to a variable.
Just check the length of the variable.

For example, if you're using the code from
http://www.mvps.org/access/api/api0002.htm at "The Access Web", you'd like
have code like:

Dim strFolder As String

strFolder = BrowseFolder("Pick a folder, any folder...")

You'd then use:

If Len(strFolder) = 0 Then
' Cancel was clicked
Else
' Put the rest of your code here.
End If
 
B

bhammer

Thanks, Doug.

I've only used this code to place the folder string directly into a textbox,
like:

txtDestFolder = BrowseForFolder("Open me")

Of course if the function is returning a string, then I can use it many
ways! (lightbulb over head).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top