[AccessD] Get Folder Name via API

Heenan, Lambert Lambert.Heenan at AIG.com
Tue Jan 6 15:17:48 CST 2004


The browse for folder dialog can be used to create new folders too. Just set
up the ulFlags item of the BrowseInfo structure like this...

.ulFlags = .ulFlags Or BIF_USENEWUI OR BIF_RETURNONLYFSDIRS

Or

.ulFlags = .ulFlags Or BIF_NEWDIALOGSTYLE OR BIF_RETURNONLYFSDIRS

And add these constants to the code

Const BIF_NEWDIALOGSTYLE = 64
Const BIF_USENEWUI = 80

The BIF_NEWDIALOGSTYLE allows you to resize the dialog adds a "Make New
Folder" button.  BIF_USENEWUI provides an edit box to type the folder name
in as well as a "Make New Folder" button. This second one only works with
Shell32.dll version 5 and greater (Win 2000 and above).

In older version clicking the new folder button will create the folder, and
the user can then select it in the folder tree and rename it.

Lambert

-----Original Message-----
From: Andy Lacey [mailto:andy at minstersystems.co.uk] 
Sent: Tuesday, January 06, 2004 1:25 PM
To: 'Access Developers discussion and problem solving'
Subject: RE: [AccessD] Get Folder Name via API


Thanks guys. You all have code that uses the same API (SHBrowseForFolder).
Works well but I had hoped to find some way of using the File Save/Save As
dialog but returning just a folder name. The advantage of that is that you
can create a new folder on the hoof. But if it was possible then I'm sure
you'd be using it too. Thanks for all your suggestions.

Andy Lacey
http://www.minstersystems.co.uk 

> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Dan Waters
> Sent: 06 January 2004 17:34
> To: 'Access Developers discussion and problem solving'
> Subject: RE: [AccessD] Get Folder Name via API
> 
> 
> Andy,
> 
> This is what I use - credits are included.  Cut and paste
> into a standard module.  I use a global string variable to 
> carry the path to a folder.
> 
> Dan Waters
> 
> '-------------------------------
> 
> Option Compare Database
> Option Explicit
> 
> Private Type BrowseInfo
>     hWndOwner 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
> 
> Const BIF_RETURNONLYFSDIRS = 1
> 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 Sub GetFolderName()
> On Error GoTo EH
> 
>     'KPD-Team 1998
>     'URL: http://www.allapi.net/
>     'KPDTeam at Allapi.net
>     
>     Dim intNull As Integer
>     Dim lngIDList As Long
>     Dim lngResult As Long
>     Dim stgPath As String
>     Dim udtBI As BrowseInfo
> 
>     With udtBI
>         'Set the owner window
>         '.hWndOwner = Me.hwnd
>         
>         'lstrcat appends the two strings and returns the
> memory address
>         '.lpszTitle = lstrcat("C:\", "")
>         
>         'Return only if the user selected a directory
>         .ulFlags = BIF_RETURNONLYFSDIRS
>         
>     End With
> 
>     'Show the 'Browse for folder' dialog
>     lngIDList = SHBrowseForFolder(udtBI)
>     
>     If lngIDList Then
>     
>         stgPath = String$(MAX_PATH, 0)
>         
>         'Get the path from the IDList
>         SHGetPathFromIDList lngIDList, stgPath
>         
>         'free the block of memory
>         CoTaskMemFree lngIDList
>         
>         '-- Get location of first null value
>         intNull = InStr(stgPath, vbNullChar)
>         
>         If intNull > 0 Then
>             '-- Trim nulls from name
>             GstgFolderName = Left$(stgPath, intNull - 1)
>         Else
>             GstgFolderName = ""
>         End If
>     Else
>         GstgFolderName = ""
>     End If
>     
>     Exit Sub
>     
> EH:
>     Application.Echo True
>     Call GlobalErrors("", Err.Number, Err.Description,
> CurrentObjectName,
> "GetFolderName")
> 
> End Sub
> 
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Andy Lacey
> Sent: Tuesday, January 06, 2004 9:42 AM
> To: Access Developers discussion and problem solving
> Subject: [AccessD] Get Folder Name via API
> 
> 
> Must've done thsi before but can't find it. I want to ask the
> user for a folder name (into which I'm going to store stuff). 
> I want to use the Windows common file dialog so that it looks 
> neat and offers to create a new folder and so on. However I 
> don't want to put a Common Dialog control on the form (always 
> has version issues) so want to use the API method. But the 
> code I have (from Dev Ashish) insists on a filename not just 
> a folder, and the other code on his site to browse a folder 
> list doesn't use the normal dialog. Anyone got code for this?
> 
> --
> Andy Lacey
> http://www.minstersystems.co.uk
> 
> 
> ________________________________________________
> Message sent using UebiMiau 2.7.2
> 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/a> ccessd
> Website: 
> http://www.databaseadvisors.com
> 
> 
> 
> _______________________________________________
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/a> ccessd
> Website: 
> http://www.databaseadvisors.com
> 
> 

_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


More information about the AccessD mailing list