Bobby Heid
bheid at appdevgrp.com
Tue Jan 6 10:00:22 CST 2004
Try this. Call by passing a reference to the calling form I.e.
strFolder=GetFolder(Me)
Let me know if this does not work as I am cutting and pasting from a module
and may have left something out.
Bobby
Private Declare Function SHGetPathFromIDList Lib "shell32" _
(ByVal pidList As Long, ByVal lpBuffer As String) As Long
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 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
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_NEWDIALOGSTYLE = &H40
Private Const BIF_EDITBOX = &H10
Private Const BIF_USENEWUI = BIF_NEWDIALOGSTYLE
Private Const BIF_STATUSTEXT As Integer = &H4
Public Function GetFolder(ByRef frmShow As Form) As String
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
With udtBI
'Set the owner window
.hWndOwner = frmShow.Hwnd
'lstrcat appends the two strings and returns the memory address
.lpszTitle = lstrcat("Directory to scan", "")
'Return only if the user selected a directory
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_USENEWUI
End With
'Show the 'Browse for folder' dialog
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
'Get the path from the IDList
SHGetPathFromIDList lpIDList, sPath
'free the block of memory
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
GetFolder = "" & sPath
End Function
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Andy Lacey
Sent: Tuesday, January 06, 2004 10: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/accessd
Website: http://www.databaseadvisors.com