PC Review


Reply
Thread Tools Rate Thread

Browse for folder doesn't always work

 
 
=?Utf-8?B?bm92YQ==?=
Guest
Posts: n/a
 
      7th Feb 2005
Hi, I'm using below function in a database on a network used by different
colleagues. For some users, the function works fine, for others, nothing
happens. Does this have to do with any setting in Windows? We are all running
Win Pro 2000 and Access 2000..

Private Type BrowseInfo
lngHwnd As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260

Private Declare Sub CoTaskMemFree Lib "ole32.dll" _
(ByVal hMem As Long)

Private Declare Function lstrcat Lib "Kernel32" _
Alias "lstrcatA" (ByVal lpString1 As String, _
ByVal lpString2 As String) As Long

Private Declare Function SHBrowseForFolder Lib "shell32" _
(lpbi As BrowseInfo) As Long

Private Declare Function SHGetPathFromIDList Lib "shell32" _
(ByVal pidList As Long, ByVal lpBuffer As String) As Long

Public Function BrowseForFolder(ByVal lngHwnd As Long, _
ByVal strPrompt As String) As String
On Error GoTo ehBrowseForFolder

Dim intNull As Integer
Dim lngIDList As Long, lngResult As Long
Dim strPath As String
Dim udtBI As BrowseInfo
'Set API properties (housed in a UDT)
With udtBI
.lngHwnd = lngHwnd
.lpszTitle = lstrcat(strPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Display the browse folder...
lngIDList = SHBrowseForFolder(udtBI)
If lngIDList <> 0 Then
'Create string of nulls so it will fill in with the path
strPath = String(MAX_PATH, 0)
'Retrieves the path selected, places in the null character filled string
lngResult = SHGetPathFromIDList(lngIDList, strPath)
'Frees memory
Call CoTaskMemFree(lngIDList)
'Find the first instance of a null character,so we can get just the path
intNull = InStr(strPath, vbNullChar)
'Greater than 0 means the path exists...
If intNull > 0 Then
'Set the value
strPath = Left(strPath, intNull - 1)
End If
End If
'Return the path name
BrowseForFolder = strPath
Exit Function 'Abort
ehBrowseForFolder:
'Return no value
BrowseForFolder = Empty

End Function
 
Reply With Quote
 
 
 
 
Brendan Reynolds
Guest
Posts: n/a
 
      7th Feb 2005
Try commenting out your error handler, or replacing it with one that will
display information about the error, something like ...

ehBrowseForFolder:
MsgBox "Error " & Err.Number & ": " & Err.Description
Exit Function

As it stands at the moment, it's just going to fail silently, giving you no
clue as to what the problem is, which makes it rather difficult to fix it!
:-)

--
Brendan Reynolds (MVP)


"nova" <(E-Mail Removed)> wrote in message
news:A9DB95BC-AC6C-4919-8D26-(E-Mail Removed)...
> Hi, I'm using below function in a database on a network used by different
> colleagues. For some users, the function works fine, for others, nothing
> happens. Does this have to do with any setting in Windows? We are all
> running
> Win Pro 2000 and Access 2000..
>
> Private Type BrowseInfo
> lngHwnd As Long
> pIDLRoot As Long
> pszDisplayName As Long
> lpszTitle As Long
> ulFlags As Long
> lpfnCallback As Long
> lParam As Long
> iImage As Long
> End Type
>
> Private Const BIF_RETURNONLYFSDIRS = 1
> Private Const MAX_PATH = 260
>
> Private Declare Sub CoTaskMemFree Lib "ole32.dll" _
> (ByVal hMem As Long)
>
> Private Declare Function lstrcat Lib "Kernel32" _
> Alias "lstrcatA" (ByVal lpString1 As String, _
> ByVal lpString2 As String) As Long
>
> Private Declare Function SHBrowseForFolder Lib "shell32" _
> (lpbi As BrowseInfo) As Long
>
> Private Declare Function SHGetPathFromIDList Lib "shell32" _
> (ByVal pidList As Long, ByVal lpBuffer As String) As Long
>
> Public Function BrowseForFolder(ByVal lngHwnd As Long, _
> ByVal strPrompt As String) As String
> On Error GoTo ehBrowseForFolder
>
> Dim intNull As Integer
> Dim lngIDList As Long, lngResult As Long
> Dim strPath As String
> Dim udtBI As BrowseInfo
> 'Set API properties (housed in a UDT)
> With udtBI
> .lngHwnd = lngHwnd
> .lpszTitle = lstrcat(strPrompt, "")
> .ulFlags = BIF_RETURNONLYFSDIRS
> End With
> 'Display the browse folder...
> lngIDList = SHBrowseForFolder(udtBI)
> If lngIDList <> 0 Then
> 'Create string of nulls so it will fill in with the path
> strPath = String(MAX_PATH, 0)
> 'Retrieves the path selected, places in the null character filled string
> lngResult = SHGetPathFromIDList(lngIDList, strPath)
> 'Frees memory
> Call CoTaskMemFree(lngIDList)
> 'Find the first instance of a null character,so we can get just the path
> intNull = InStr(strPath, vbNullChar)
> 'Greater than 0 means the path exists...
> If intNull > 0 Then
> 'Set the value
> strPath = Left(strPath, intNull - 1)
> End If
> End If
> 'Return the path name
> BrowseForFolder = strPath
> Exit Function 'Abort
> ehBrowseForFolder:
> 'Return no value
> BrowseForFolder = Empty
>
> End Function



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Right click on mouse doesn't open and Browse in Display Control Panel doesn't work. neverbeen Windows XP Performance 4 5th Jan 2010 02:32 AM
what if the browse doesn't work on other websites? sylvia s Microsoft Word Document Management 1 22nd Jul 2009 09:04 PM
Browse button doesn't seem to work Jimmy Clay Microsoft Word New Users 2 8th Oct 2007 02:28 AM
Browse doesn't work for hyperlinks or pictures John Lenehan Microsoft Frontpage 1 21st Apr 2004 02:46 PM
Browse... button doesn't work Pat Schelfhout Windows XP Internet Explorer 0 8th Sep 2003 08:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:09 PM.