[AccessD] Get Folder Name via API

Dan Waters dwaters at usinternet.com
Tue Jan 6 15:16:45 CST 2004


Andy - I guess I'm not sure what you need.  This code returns the path to a
folder, and you can pull the last folder name out of that string.  The
dialog box to find the folder is different, but it does find and select
folders.

You can use File Search Objects to create a new folder in code.  Maybe a
combination of both would work out.

Also, part of my system uses the Find File dialog box, and I am able to use
it to create a new folder wherever I want.  I'm not using the Find File
dialog box that is an activex object, but the one that is called from a
Windows API.  I got the API code for the Find File dialog box from Candace
Tripp's web site.

HTH!
Dan


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Andy Lacey
Sent: Tuesday, January 06, 2004 12: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