473,749 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA332.DLL and AccessXP And Getting Current Folder

I designed a small app and I wanted to do a BrowseFolder (see
http://www.mvps.org/access/api/api0002.htm), basically do a file open
diaglog and select a directory/folder. The problem is that you can't
specify the starting folder.

Stephan Leban provided a neat solution that does allow me to browse
using a starting folder.

I am using A97 and it works fine. However, I put it onto a system that
uses AccessXP. And it chokes on references to VBA332.DLL. I searched
the drive on the XP system and there is no VBA332.DLL. That makes
Stephan's utility unworkable.

Is there anything I can use to substitute vba332.dll? Below are the
functions that make refererence to it. Does XP have a "built-in"
browsefolder command where one can specify a starting folder?

Private Declare Function GetCurrentVbaPr oject _
Lib "vba332.dll " Alias "EbGetExecuting Proj" _
(hProject As Long) As Long
Private Declare Function GetFuncID _
Lib "vba332.dll " Alias "TipGetFunction Id" _
(ByVal hProject As Long, ByVal strFunctionName As String, _
ByRef strFunctionId As String) As Long
Private Declare Function GetAddr _
Lib "vba332.dll " Alias "TipGetLpfnOfFu nctionId" _
(ByVal hProject As Long, ByVal strFunctionId As String, _
ByRef lpfn As Long) As Long
Nov 13 '05 #1
8 3984
I'm not completely sure about compatibility with A97, but I use the Common
Dialog module from "Access 2000 Developer's Handbook" (Getz, Litwin,
Gilbert). I started using it because of the many problems I had experienced
with incompatibility between different client systems. It works flawlessly
on every system I've put it on and allows you to specify a starting
directory.
"Salad" <oi*@vinegar.co m> wrote in message
news:UH******** ********@newsre ad1.news.pas.ea rthlink.net...
I designed a small app and I wanted to do a BrowseFolder (see
http://www.mvps.org/access/api/api0002.htm), basically do a file open
diaglog and select a directory/folder. The problem is that you can't
specify the starting folder.

Stephan Leban provided a neat solution that does allow me to browse
using a starting folder.

I am using A97 and it works fine. However, I put it onto a system that
uses AccessXP. And it chokes on references to VBA332.DLL. I searched
the drive on the XP system and there is no VBA332.DLL. That makes
Stephan's utility unworkable.

Is there anything I can use to substitute vba332.dll? Below are the
functions that make refererence to it. Does XP have a "built-in"
browsefolder command where one can specify a starting folder?

Private Declare Function GetCurrentVbaPr oject _
Lib "vba332.dll " Alias "EbGetExecuting Proj" _
(hProject As Long) As Long
Private Declare Function GetFuncID _
Lib "vba332.dll " Alias "TipGetFunction Id" _
(ByVal hProject As Long, ByVal strFunctionName As String, _
ByRef strFunctionId As String) As Long
Private Declare Function GetAddr _
Lib "vba332.dll " Alias "TipGetLpfnOfFu nctionId" _
(ByVal hProject As Long, ByVal strFunctionId As String, _
ByRef lpfn As Long) As Long


Nov 13 '05 #2
Randy Harris wrote:
I'm not completely sure about compatibility with A97, but I use the Common
Dialog module from "Access 2000 Developer's Handbook" (Getz, Litwin,
Gilbert). I started using it because of the many problems I had experienced
with incompatibility between different client systems. It works flawlessly
on every system I've put it on and allows you to specify a starting
directory.


Thanks for the prompt reply. Can you specify the starting directory
with it? For example, I don't want to send someone to MyDocuments (the
usual default) where the user needs to go up several levels then maybe
down several levels. For example, if the current folder is
C:\Test\Testing \TextFiles...I want that to be the starting directory.
Nov 13 '05 #3

"Salad" <oi*@vinegar.co m> wrote in message
news:C9******** *******@newsrea d1.news.pas.ear thlink.net...
Randy Harris wrote:
I'm not completely sure about compatibility with A97, but I use the Common Dialog module from "Access 2000 Developer's Handbook" (Getz, Litwin,
Gilbert). I started using it because of the many problems I had experienced with incompatibility between different client systems. It works flawlessly on every system I've put it on and allows you to specify a starting
directory.


Thanks for the prompt reply. Can you specify the starting directory
with it? For example, I don't want to send someone to MyDocuments (the
usual default) where the user needs to go up several levels then maybe
down several levels. For example, if the current folder is
C:\Test\Testing \TextFiles...I want that to be the starting directory.


Yes, you sure can.
Nov 13 '05 #4
You are trying to use the A97 version on A2K or higher. Simply download the
A2K version and you will have no trouble. The issue you mentioned has to do
with the fact that AddressOf was natively supported prior to A2K.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Salad" <oi*@vinegar.co m> wrote in message
news:UH******** ********@newsre ad1.news.pas.ea rthlink.net...
I designed a small app and I wanted to do a BrowseFolder (see
http://www.mvps.org/access/api/api0002.htm), basically do a file open
diaglog and select a directory/folder. The problem is that you can't
specify the starting folder.

Stephan Leban provided a neat solution that does allow me to browse using
a starting folder.

I am using A97 and it works fine. However, I put it onto a system that
uses AccessXP. And it chokes on references to VBA332.DLL. I searched the
drive on the XP system and there is no VBA332.DLL. That makes Stephan's
utility unworkable.

Is there anything I can use to substitute vba332.dll? Below are the
functions that make refererence to it. Does XP have a "built-in"
browsefolder command where one can specify a starting folder?

Private Declare Function GetCurrentVbaPr oject _
Lib "vba332.dll " Alias "EbGetExecuting Proj" _
(hProject As Long) As Long
Private Declare Function GetFuncID _
Lib "vba332.dll " Alias "TipGetFunction Id" _
(ByVal hProject As Long, ByVal strFunctionName As String, _
ByRef strFunctionId As String) As Long
Private Declare Function GetAddr _
Lib "vba332.dll " Alias "TipGetLpfnOfFu nctionId" _
(ByVal hProject As Long, ByVal strFunctionId As String, _
ByRef lpfn As Long) As Long

Nov 13 '05 #5
The following works
'************** *************** *********
' Code Start
Option Explicit

'************** *************** *
'Code Start
'************** *************** *
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As Long
lpszTitle As Long
' lpszTitle As Byte
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'************** *************** *
'Functions in BrowseFolder
'************** *************** *
Private Declare Function SHGetPathFromID List _
Lib "shell32.dl l" Alias "SHGetPathFromI DListA" _
(ByVal pidl As Long, ByVal pszPath As String) _
As Long
Private Declare Function SHBrowseForFold er _
Lib "shell32.dl l" Alias "SHBrowseForFol derA" _
(lpBrowseInfo As BROWSEINFO) _
As Long
Private Declare Sub ZeroMemory _
Lib "kernel32" Alias "RtlZeroMem ory" _
(dest As Long, ByVal numBytes As Long)
Private Declare Function lstrcat _
Lib "kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, _
ByVal lpString2 As String) _
As Long
'************** *************** *
'/Functions in BrowseFolder
'************** *************** *

Private Declare Function GetFileVersionI nfoSize Lib "version.dl l" _
Alias "GetFileVersion InfoSizeA" _
(ByVal lptstrFilename As String, _
lpdwHandle As Long) As Long

Private Declare Function GetFileVersionI nfo Lib "version.dl l" _
Alias "GetFileVersion InfoA" _
(ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
lpData As Any) As Long

Private Declare Function VerQueryValue Lib "version.dl l" _
Alias "VerQueryValueA " _
(pBlock As Any, _
ByVal lpSubBlock As String, _
lpBuffer As Any, _
nVerSize As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMem ory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

'************** *************** *
'Functions used in call back
'************** *************** *
Private Declare Function GetCurrentDirec tory _
Lib "kernel32" Alias "GetCurrentDire ctoryA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessag eA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) _
As Long
'************** *************** *
'/Functions used in call back
'************** *************** *

'************** *************** *
'Root pidls
'************** *************** *
Private Const CSIDL_DESKTOP = &H0
Private Const CSIDL_PROGRAMS = &H2
Private Const CSIDL_CONTROLS = &H3
Private Const CSIDL_PRINTERS = &H4
Private Const CSIDL_PERSONAL = &H5
Private Const CSIDL_FAVORITES = &H6
Private Const CSIDL_STARTUP = &H7
Private Const CSIDL_RECENT = &H8
Private Const CSIDL_SENDTO = &H9
Private Const CSIDL_BITBUCKET = &HA
Private Const CSIDL_STARTMENU = &HB
Private Const CSIDL_DESKTOPDI RECTORY = &H10
Private Const CSIDL_DRIVES = &H11
Private Const CSIDL_NETWORK = &H12
Private Const CSIDL_NETHOOD = &H13
Private Const CSIDL_FONTS = &H14
Private Const CSIDL_TEMPLATES = &H15
'************** *************** *
'Root pidls
'************** *************** *

'************** *************** *
'uFlag consts
'************** *************** *
Private Const BIF_DONTGOBELOW DOMAIN = &H2
Private Const BIF_STATUSTEXT = &H4
Private Const BIF_RETURNFSANC ESTORS = &H8
Private Const BIF_BROWSEFORCO MPUTER = &H1000
Private Const BIF_BROWSEFORPR INTER = &H2000
Private Const BIF_RETURNONLYF SDIRS = &H1
Private Const BIF_EDITBOX = &H10
Private Const BIF_VALIDATE = &H20
Private Const BIF_NEWDIALOGST YLE As Long = &H40
Private Const BIF_USENEWUI As Long = (BIF_NEWDIALOGS TYLE Or BIF_EDITBOX)
'************** *************** *
'/uFlag consts
'************** *************** *

Private Const WM_USER = &H400

'************** *************** *
'Messages from dialog consts
'************** *************** *
Private Const BFFM_INITIALIZE D = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_VALIDATEFA ILEDA = 3
Private Const BFFM_VALIDATEFA ILED = BFFM_VALIDATEFA ILEDA
'************** *************** *
'/Messages from dialog consts
'************** *************** *

'************** *************** *
'Messages to dialog consts
'************** *************** *
Private Const BFFM_SETSELECTI ONA = WM_USER + 102
Private Const BFFM_SETSELECTI ON = BFFM_SETSELECTI ONA
Private Const BFFM_SETSTATUST EXTA = WM_USER + 100
Private Const BFFM_SETSTATUST EXT = BFFM_SETSTATUST EXTA
'************** *************** *
'/Messages to dialog consts
'************** *************** *

Private Const MAX_PATH = 260

Private strStartDir As String
'

Public Function BrowseFolder(sz DialogTitle As String, _
Optional StartDir As String = vbNullString, Optional hWnd As Long = 0) As
String
'************** *************** **************
'Name: BrowseFolder (Function)
'Purpose: Open API browse for folder dialog
'Author: Terry Kreft
'Date: January 28, 2001, 09:50:20
'Called by: Any
'Calls: AddrOf _
Various API calls defined on this module
'Inputs: szDialogTitle - dialog prompt _
StartDir - Directory to start the _
browse in (Optional)
'Output: Directory selected in browse folder
'************** *************** **************

Dim x As Long
Dim BI As BROWSEINFO
Dim dwIList As Long
Dim szPath As String
Dim wPos As Integer
Dim lngPtr As Long
Dim bytBuffer() As Byte

strStartDir = StartDir
BrowseFolder = ""

Call ZeroMemory(VarP tr(BI), Len(BI))

' This has to be 1 element larger than the length
' of the string so that it contains the terminating
' Null character
ReDim bytBuffer(0 To Len(szDialogTit le))
For lngPtr = 1 To Len(szDialogTit le)
bytBuffer(lngPt r - 1) = Asc(Mid(szDialo gTitle, lngPtr, 1))
Next

With BI
.pidlRoot = CSIDL_DESKTOP
.hOwner = hWnd
.lpszTitle = VarPtr(bytBuffe r(0))
.ulFlags = BIF_RETURNONLYF SDIRS Or BIF_STATUSTEXT _
Or BIF_EDITBOX Or BIF_VALIDATE
If IsShellVersion( 5) Then
.ulFlags = .ulFlags Or BIF_NEWDIALOGST YLE
End If
.lpfn = AddrOf2k(Addres sOf BrowseCallbackP roc)
End With
dwIList = SHBrowseForFold er(BI)
If dwIList Then
szPath = Space$(512)
x = SHGetPathFromID List(dwIList, szPath)
If x Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
End If
End If
End Function

Function BrowseCallbackP roc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal lp As Long, ByVal pData As Long) As Long
'************** *************** **************
'Name: BrowseCallbackP roc (Function)
'Purpose: Call back function for BrowseFolder
'Author: Terry Kreft
'Date: January 28, 2001, 09:52:56
'Called by: API Browse Folder dialog
'Calls: Various API functions
'Inputs: See MSDN for description of inputs
'Output:
'************** *************** **************
Dim lngRet As Long
Dim nBufferLength As Long
Dim lpBuffer As String

Const apiTrue = 1
Const apiFalse = 0
Const BAD_DIR = "The directory selected is invalid." _
& vbCrLf _
& "Do you want to try again"

lngRet = apiFalse
Select Case uMsg
Case BFFM_INITIALIZE D
If Len(strStartDir ) < 1 Then
nBufferLength = MAX_PATH
lpBuffer = String(MAX_PATH , 0)
If GetCurrentDirec tory(nBufferLen gth, lpBuffer) Then
Call SendMessage(hWn d, BFFM_SETSELECTI ON, apiTrue, ByVal lpBuffer)
End If
Else
Call SendMessage(hWn d, BFFM_SETSELECTI ON, apiTrue, ByVal strStartDir)
End If
Case BFFM_SELCHANGED
'Set the status window to the currently selected path.
lpBuffer = String(MAX_PATH , 0)
If SHGetPathFromID List(lp, lpBuffer) Then
lpBuffer = Left(lpBuffer, InStr(lpBuffer, Chr(0)) - 1)
Call SendMessage(hWn d, BFFM_SETSTATUST EXT, apiTrue, ByVal lpBuffer)
End If
Case BFFM_VALIDATEFA ILED
'If the user types an invalid path
If MsgBox(BAD_DIR, vbYesNo) = vbYes Then
lngRet = apiTrue
End If
' Case BFFM_IUNKNOWN

Case Else
' Debug.Print uMsg
End Select
BrowseCallbackP roc = lngRet
End Function

Function AddrOf2k(ByVal lngFnPtr As Long) As Long
AddrOf2k = lngFnPtr
End Function
'************** *************** *
'Code End
'************** *************** *
Private Function IsShellVersion( ByVal Version As Long) As Boolean

'returns True if the Shell version
'(shell32.dll) is equal or later than
'the value passed as 'version'
Dim nBufferSize As Long
Dim nUnused As Long
Dim lpBuffer As Long
Dim nVerMajor As Integer
Dim bBuffer() As Byte

Const sDLLFile As String = "shell32.dl l"

nBufferSize = GetFileVersionI nfoSize(sDLLFil e, nUnused)

If nBufferSize > 0 Then

ReDim bBuffer(nBuffer Size - 1) As Byte

Call GetFileVersionI nfo(sDLLFile, 0&, nBufferSize, bBuffer(0))

If VerQueryValue(b Buffer(0), "\", lpBuffer, nUnused) = 1 Then

CopyMemory nVerMajor, ByVal lpBuffer + 10, 2

IsShellVersion = nVerMajor >= Version

End If 'VerQueryValue
End If 'nBufferSize

End Function
' Code Start
'************** *************** *********

Copy and paste the code above into a module then call the BrowseFolder
function

Sample call:-

Dim strFolder as String

strFolder = BrowseFolder("F ind the Folder", "c:\program files")
--
Terry Kreft

"Salad" <oi*@vinegar.co m> wrote in message
news:UH******** ********@newsre ad1.news.pas.ea rthlink.net...
I designed a small app and I wanted to do a BrowseFolder (see
http://www.mvps.org/access/api/api0002.htm), basically do a file open
diaglog and select a directory/folder. The problem is that you can't
specify the starting folder.

Stephan Leban provided a neat solution that does allow me to browse using
a starting folder.

I am using A97 and it works fine. However, I put it onto a system that
uses AccessXP. And it chokes on references to VBA332.DLL. I searched the
drive on the XP system and there is no VBA332.DLL. That makes Stephan's
utility unworkable.

Is there anything I can use to substitute vba332.dll? Below are the
functions that make refererence to it. Does XP have a "built-in"
browsefolder command where one can specify a starting folder?

Private Declare Function GetCurrentVbaPr oject _
Lib "vba332.dll " Alias "EbGetExecuting Proj" _
(hProject As Long) As Long
Private Declare Function GetFuncID _
Lib "vba332.dll " Alias "TipGetFunction Id" _
(ByVal hProject As Long, ByVal strFunctionName As String, _
ByRef strFunctionId As String) As Long
Private Declare Function GetAddr _
Lib "vba332.dll " Alias "TipGetLpfnOfFu nctionId" _
(ByVal hProject As Long, ByVal strFunctionId As String, _
ByRef lpfn As Long) As Long

Nov 13 '05 #6
Salad wrote:

Thanks all.
Nov 13 '05 #7
Terry Kreft wrote:

Hi Terry. I can't get your code to work tho the fix looks minor. The
problem exists on the statement line
.lpfn = AddrOf2k(Addres sOf BrowseCallbackP roc)

If I comment the line out, it works as a normal BrowseFolder and puts me
at MyDocuments. I don't start at "c:\program files" using your example.

The following works
'************** *************** *********
' Code Start
Option Explicit

'************** *************** *
'Code Start
'************** *************** *
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As Long
lpszTitle As Long
' lpszTitle As Byte
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'************** *************** *
'Functions in BrowseFolder
'************** *************** *
Private Declare Function SHGetPathFromID List _
Lib "shell32.dl l" Alias "SHGetPathFromI DListA" _
(ByVal pidl As Long, ByVal pszPath As String) _
As Long
Private Declare Function SHBrowseForFold er _
Lib "shell32.dl l" Alias "SHBrowseForFol derA" _
(lpBrowseInfo As BROWSEINFO) _
As Long
Private Declare Sub ZeroMemory _
Lib "kernel32" Alias "RtlZeroMem ory" _
(dest As Long, ByVal numBytes As Long)
Private Declare Function lstrcat _
Lib "kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, _
ByVal lpString2 As String) _
As Long
'************** *************** *
'/Functions in BrowseFolder
'************** *************** *

Private Declare Function GetFileVersionI nfoSize Lib "version.dl l" _
Alias "GetFileVersion InfoSizeA" _
(ByVal lptstrFilename As String, _
lpdwHandle As Long) As Long

Private Declare Function GetFileVersionI nfo Lib "version.dl l" _
Alias "GetFileVersion InfoA" _
(ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
lpData As Any) As Long

Private Declare Function VerQueryValue Lib "version.dl l" _
Alias "VerQueryValueA " _
(pBlock As Any, _
ByVal lpSubBlock As String, _
lpBuffer As Any, _
nVerSize As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMem ory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

'************** *************** *
'Functions used in call back
'************** *************** *
Private Declare Function GetCurrentDirec tory _
Lib "kernel32" Alias "GetCurrentDire ctoryA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessag eA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) _
As Long
'************** *************** *
'/Functions used in call back
'************** *************** *

'************** *************** *
'Root pidls
'************** *************** *
Private Const CSIDL_DESKTOP = &H0
Private Const CSIDL_PROGRAMS = &H2
Private Const CSIDL_CONTROLS = &H3
Private Const CSIDL_PRINTERS = &H4
Private Const CSIDL_PERSONAL = &H5
Private Const CSIDL_FAVORITES = &H6
Private Const CSIDL_STARTUP = &H7
Private Const CSIDL_RECENT = &H8
Private Const CSIDL_SENDTO = &H9
Private Const CSIDL_BITBUCKET = &HA
Private Const CSIDL_STARTMENU = &HB
Private Const CSIDL_DESKTOPDI RECTORY = &H10
Private Const CSIDL_DRIVES = &H11
Private Const CSIDL_NETWORK = &H12
Private Const CSIDL_NETHOOD = &H13
Private Const CSIDL_FONTS = &H14
Private Const CSIDL_TEMPLATES = &H15
'************** *************** *
'Root pidls
'************** *************** *

'************** *************** *
'uFlag consts
'************** *************** *
Private Const BIF_DONTGOBELOW DOMAIN = &H2
Private Const BIF_STATUSTEXT = &H4
Private Const BIF_RETURNFSANC ESTORS = &H8
Private Const BIF_BROWSEFORCO MPUTER = &H1000
Private Const BIF_BROWSEFORPR INTER = &H2000
Private Const BIF_RETURNONLYF SDIRS = &H1
Private Const BIF_EDITBOX = &H10
Private Const BIF_VALIDATE = &H20
Private Const BIF_NEWDIALOGST YLE As Long = &H40
Private Const BIF_USENEWUI As Long = (BIF_NEWDIALOGS TYLE Or BIF_EDITBOX)
'************** *************** *
'/uFlag consts
'************** *************** *

Private Const WM_USER = &H400

'************** *************** *
'Messages from dialog consts
'************** *************** *
Private Const BFFM_INITIALIZE D = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_VALIDATEFA ILEDA = 3
Private Const BFFM_VALIDATEFA ILED = BFFM_VALIDATEFA ILEDA
'************** *************** *
'/Messages from dialog consts
'************** *************** *

'************** *************** *
'Messages to dialog consts
'************** *************** *
Private Const BFFM_SETSELECTI ONA = WM_USER + 102
Private Const BFFM_SETSELECTI ON = BFFM_SETSELECTI ONA
Private Const BFFM_SETSTATUST EXTA = WM_USER + 100
Private Const BFFM_SETSTATUST EXT = BFFM_SETSTATUST EXTA
'************** *************** *
'/Messages to dialog consts
'************** *************** *

Private Const MAX_PATH = 260

Private strStartDir As String
'

Public Function BrowseFolder(sz DialogTitle As String, _
Optional StartDir As String = vbNullString, Optional hWnd As Long = 0) As
String
'************** *************** **************
'Name: BrowseFolder (Function)
'Purpose: Open API browse for folder dialog
'Author: Terry Kreft
'Date: January 28, 2001, 09:50:20
'Called by: Any
'Calls: AddrOf _
Various API calls defined on this module
'Inputs: szDialogTitle - dialog prompt _
StartDir - Directory to start the _
browse in (Optional)
'Output: Directory selected in browse folder
'************** *************** **************

Dim x As Long
Dim BI As BROWSEINFO
Dim dwIList As Long
Dim szPath As String
Dim wPos As Integer
Dim lngPtr As Long
Dim bytBuffer() As Byte

strStartDir = StartDir
BrowseFolder = ""

Call ZeroMemory(VarP tr(BI), Len(BI))

' This has to be 1 element larger than the length
' of the string so that it contains the terminating
' Null character
ReDim bytBuffer(0 To Len(szDialogTit le))
For lngPtr = 1 To Len(szDialogTit le)
bytBuffer(lngPt r - 1) = Asc(Mid(szDialo gTitle, lngPtr, 1))
Next

With BI
.pidlRoot = CSIDL_DESKTOP
.hOwner = hWnd
.lpszTitle = VarPtr(bytBuffe r(0))
.ulFlags = BIF_RETURNONLYF SDIRS Or BIF_STATUSTEXT _
Or BIF_EDITBOX Or BIF_VALIDATE
If IsShellVersion( 5) Then
.ulFlags = .ulFlags Or BIF_NEWDIALOGST YLE
End If
.lpfn = AddrOf2k(Addres sOf BrowseCallbackP roc)
End With
dwIList = SHBrowseForFold er(BI)
If dwIList Then
szPath = Space$(512)
x = SHGetPathFromID List(dwIList, szPath)
If x Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
End If
End If
End Function

Function BrowseCallbackP roc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal lp As Long, ByVal pData As Long) As Long
'************** *************** **************
'Name: BrowseCallbackP roc (Function)
'Purpose: Call back function for BrowseFolder
'Author: Terry Kreft
'Date: January 28, 2001, 09:52:56
'Called by: API Browse Folder dialog
'Calls: Various API functions
'Inputs: See MSDN for description of inputs
'Output:
'************** *************** **************
Dim lngRet As Long
Dim nBufferLength As Long
Dim lpBuffer As String

Const apiTrue = 1
Const apiFalse = 0
Const BAD_DIR = "The directory selected is invalid." _
& vbCrLf _
& "Do you want to try again"

lngRet = apiFalse
Select Case uMsg
Case BFFM_INITIALIZE D
If Len(strStartDir ) < 1 Then
nBufferLength = MAX_PATH
lpBuffer = String(MAX_PATH , 0)
If GetCurrentDirec tory(nBufferLen gth, lpBuffer) Then
Call SendMessage(hWn d, BFFM_SETSELECTI ON, apiTrue, ByVal lpBuffer)
End If
Else
Call SendMessage(hWn d, BFFM_SETSELECTI ON, apiTrue, ByVal strStartDir)
End If
Case BFFM_SELCHANGED
'Set the status window to the currently selected path.
lpBuffer = String(MAX_PATH , 0)
If SHGetPathFromID List(lp, lpBuffer) Then
lpBuffer = Left(lpBuffer, InStr(lpBuffer, Chr(0)) - 1)
Call SendMessage(hWn d, BFFM_SETSTATUST EXT, apiTrue, ByVal lpBuffer)
End If
Case BFFM_VALIDATEFA ILED
'If the user types an invalid path
If MsgBox(BAD_DIR, vbYesNo) = vbYes Then
lngRet = apiTrue
End If
' Case BFFM_IUNKNOWN

Case Else
' Debug.Print uMsg
End Select
BrowseCallbackP roc = lngRet
End Function

Function AddrOf2k(ByVal lngFnPtr As Long) As Long
AddrOf2k = lngFnPtr
End Function
'************** *************** *
'Code End
'************** *************** *
Private Function IsShellVersion( ByVal Version As Long) As Boolean

'returns True if the Shell version
'(shell32.dll) is equal or later than
'the value passed as 'version'
Dim nBufferSize As Long
Dim nUnused As Long
Dim lpBuffer As Long
Dim nVerMajor As Integer
Dim bBuffer() As Byte

Const sDLLFile As String = "shell32.dl l"

nBufferSize = GetFileVersionI nfoSize(sDLLFil e, nUnused)

If nBufferSize > 0 Then

ReDim bBuffer(nBuffer Size - 1) As Byte

Call GetFileVersionI nfo(sDLLFile, 0&, nBufferSize, bBuffer(0))

If VerQueryValue(b Buffer(0), "\", lpBuffer, nUnused) = 1 Then

CopyMemory nVerMajor, ByVal lpBuffer + 10, 2

IsShellVersion = nVerMajor >= Version

End If 'VerQueryValue
End If 'nBufferSize

End Function
' Code Start
'************** *************** *********

Copy and paste the code above into a module then call the BrowseFolder
function

Sample call:-

Dim strFolder as String

strFolder = BrowseFolder("F ind the Folder", "c:\program files")

Nov 13 '05 #8
Salad,
It won't work on A97, you need to use the addrof code from Michael Kaplan
and Ken Getz for that
(http://www.trigeminal.com/lang/1033/...?ItemID=19#19), but it should
work in AccessXp, I've tested it on A2003 and it certainly worked there.

The line you remmed out is the one which hooks the browse dialog to the
callback function. The callback function changes the start dir to whatever
you want, so I'm not surprised it didn't work after you remmed the line.

--
Terry Kreft

"Salad" <oi*@vinegar.co m> wrote in message
news:mj******** *********@newsr ead2.news.pas.e arthlink.net...
Terry Kreft wrote:

Hi Terry. I can't get your code to work tho the fix looks minor. The
problem exists on the statement line
.lpfn = AddrOf2k(Addres sOf BrowseCallbackP roc)

If I comment the line out, it works as a normal BrowseFolder and puts me
at MyDocuments. I don't start at "c:\program files" using your example.

The following works
'************** *************** *********
' Code Start
Option Explicit

'************** *************** *
'Code Start
'************** *************** *
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As Long
lpszTitle As Long
' lpszTitle As Byte
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'************** *************** *
'Functions in BrowseFolder
'************** *************** *
Private Declare Function SHGetPathFromID List _
Lib "shell32.dl l" Alias "SHGetPathFromI DListA" _
(ByVal pidl As Long, ByVal pszPath As String) _
As Long
Private Declare Function SHBrowseForFold er _
Lib "shell32.dl l" Alias "SHBrowseForFol derA" _
(lpBrowseInfo As BROWSEINFO) _
As Long
Private Declare Sub ZeroMemory _
Lib "kernel32" Alias "RtlZeroMem ory" _
(dest As Long, ByVal numBytes As Long)
Private Declare Function lstrcat _
Lib "kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, _
ByVal lpString2 As String) _
As Long
'************** *************** *
'/Functions in BrowseFolder
'************** *************** *

Private Declare Function GetFileVersionI nfoSize Lib "version.dl l" _
Alias "GetFileVersion InfoSizeA" _
(ByVal lptstrFilename As String, _
lpdwHandle As Long) As Long

Private Declare Function GetFileVersionI nfo Lib "version.dl l" _
Alias "GetFileVersion InfoA" _
(ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
lpData As Any) As Long

Private Declare Function VerQueryValue Lib "version.dl l" _
Alias "VerQueryValueA " _
(pBlock As Any, _
ByVal lpSubBlock As String, _
lpBuffer As Any, _
nVerSize As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMem ory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

'************** *************** *
'Functions used in call back
'************** *************** *
Private Declare Function GetCurrentDirec tory _
Lib "kernel32" Alias "GetCurrentDire ctoryA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessag eA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) _
As Long
'************** *************** *
'/Functions used in call back
'************** *************** *

'************** *************** *
'Root pidls
'************** *************** *
Private Const CSIDL_DESKTOP = &H0
Private Const CSIDL_PROGRAMS = &H2
Private Const CSIDL_CONTROLS = &H3
Private Const CSIDL_PRINTERS = &H4
Private Const CSIDL_PERSONAL = &H5
Private Const CSIDL_FAVORITES = &H6
Private Const CSIDL_STARTUP = &H7
Private Const CSIDL_RECENT = &H8
Private Const CSIDL_SENDTO = &H9
Private Const CSIDL_BITBUCKET = &HA
Private Const CSIDL_STARTMENU = &HB
Private Const CSIDL_DESKTOPDI RECTORY = &H10
Private Const CSIDL_DRIVES = &H11
Private Const CSIDL_NETWORK = &H12
Private Const CSIDL_NETHOOD = &H13
Private Const CSIDL_FONTS = &H14
Private Const CSIDL_TEMPLATES = &H15
'************** *************** *
'Root pidls
'************** *************** *

'************** *************** *
'uFlag consts
'************** *************** *
Private Const BIF_DONTGOBELOW DOMAIN = &H2
Private Const BIF_STATUSTEXT = &H4
Private Const BIF_RETURNFSANC ESTORS = &H8
Private Const BIF_BROWSEFORCO MPUTER = &H1000
Private Const BIF_BROWSEFORPR INTER = &H2000
Private Const BIF_RETURNONLYF SDIRS = &H1
Private Const BIF_EDITBOX = &H10
Private Const BIF_VALIDATE = &H20
Private Const BIF_NEWDIALOGST YLE As Long = &H40
Private Const BIF_USENEWUI As Long = (BIF_NEWDIALOGS TYLE Or BIF_EDITBOX)
'************** *************** *
'/uFlag consts
'************** *************** *

Private Const WM_USER = &H400

'************** *************** *
'Messages from dialog consts
'************** *************** *
Private Const BFFM_INITIALIZE D = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_VALIDATEFA ILEDA = 3
Private Const BFFM_VALIDATEFA ILED = BFFM_VALIDATEFA ILEDA
'************** *************** *
'/Messages from dialog consts
'************** *************** *

'************** *************** *
'Messages to dialog consts
'************** *************** *
Private Const BFFM_SETSELECTI ONA = WM_USER + 102
Private Const BFFM_SETSELECTI ON = BFFM_SETSELECTI ONA
Private Const BFFM_SETSTATUST EXTA = WM_USER + 100
Private Const BFFM_SETSTATUST EXT = BFFM_SETSTATUST EXTA
'************** *************** *
'/Messages to dialog consts
'************** *************** *

Private Const MAX_PATH = 260

Private strStartDir As String
'

Public Function BrowseFolder(sz DialogTitle As String, _
Optional StartDir As String = vbNullString, Optional hWnd As Long = 0)
As String
'************** *************** **************
'Name: BrowseFolder (Function)
'Purpose: Open API browse for folder dialog
'Author: Terry Kreft
'Date: January 28, 2001, 09:50:20
'Called by: Any
'Calls: AddrOf _
Various API calls defined on this module
'Inputs: szDialogTitle - dialog prompt _
StartDir - Directory to start the _
browse in (Optional)
'Output: Directory selected in browse folder
'************** *************** **************

Dim x As Long
Dim BI As BROWSEINFO
Dim dwIList As Long
Dim szPath As String
Dim wPos As Integer
Dim lngPtr As Long
Dim bytBuffer() As Byte

strStartDir = StartDir
BrowseFolder = ""

Call ZeroMemory(VarP tr(BI), Len(BI))

' This has to be 1 element larger than the length
' of the string so that it contains the terminating
' Null character
ReDim bytBuffer(0 To Len(szDialogTit le))
For lngPtr = 1 To Len(szDialogTit le)
bytBuffer(lngPt r - 1) = Asc(Mid(szDialo gTitle, lngPtr, 1))
Next

With BI
.pidlRoot = CSIDL_DESKTOP
.hOwner = hWnd
.lpszTitle = VarPtr(bytBuffe r(0))
.ulFlags = BIF_RETURNONLYF SDIRS Or BIF_STATUSTEXT _
Or BIF_EDITBOX Or BIF_VALIDATE
If IsShellVersion( 5) Then
.ulFlags = .ulFlags Or BIF_NEWDIALOGST YLE
End If
.lpfn = AddrOf2k(Addres sOf BrowseCallbackP roc)
End With
dwIList = SHBrowseForFold er(BI)
If dwIList Then
szPath = Space$(512)
x = SHGetPathFromID List(dwIList, szPath)
If x Then
wPos = InStr(szPath, Chr(0))
BrowseFolder = Left$(szPath, wPos - 1)
End If
End If
End Function

Function BrowseCallbackP roc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal lp As Long, ByVal pData As Long) As Long
'************** *************** **************
'Name: BrowseCallbackP roc (Function)
'Purpose: Call back function for BrowseFolder
'Author: Terry Kreft
'Date: January 28, 2001, 09:52:56
'Called by: API Browse Folder dialog
'Calls: Various API functions
'Inputs: See MSDN for description of inputs
'Output:
'************** *************** **************
Dim lngRet As Long
Dim nBufferLength As Long
Dim lpBuffer As String

Const apiTrue = 1
Const apiFalse = 0
Const BAD_DIR = "The directory selected is invalid." _
& vbCrLf _
& "Do you want to try again"

lngRet = apiFalse
Select Case uMsg
Case BFFM_INITIALIZE D
If Len(strStartDir ) < 1 Then
nBufferLength = MAX_PATH
lpBuffer = String(MAX_PATH , 0)
If GetCurrentDirec tory(nBufferLen gth, lpBuffer) Then
Call SendMessage(hWn d, BFFM_SETSELECTI ON, apiTrue, ByVal
lpBuffer)
End If
Else
Call SendMessage(hWn d, BFFM_SETSELECTI ON, apiTrue, ByVal
strStartDir)
End If
Case BFFM_SELCHANGED
'Set the status window to the currently selected path.
lpBuffer = String(MAX_PATH , 0)
If SHGetPathFromID List(lp, lpBuffer) Then
lpBuffer = Left(lpBuffer, InStr(lpBuffer, Chr(0)) - 1)
Call SendMessage(hWn d, BFFM_SETSTATUST EXT, apiTrue, ByVal lpBuffer)
End If
Case BFFM_VALIDATEFA ILED
'If the user types an invalid path
If MsgBox(BAD_DIR, vbYesNo) = vbYes Then
lngRet = apiTrue
End If
' Case BFFM_IUNKNOWN

Case Else
' Debug.Print uMsg
End Select
BrowseCallbackP roc = lngRet
End Function

Function AddrOf2k(ByVal lngFnPtr As Long) As Long
AddrOf2k = lngFnPtr
End Function
'************** *************** *
'Code End
'************** *************** *
Private Function IsShellVersion( ByVal Version As Long) As Boolean

'returns True if the Shell version
'(shell32.dll) is equal or later than
'the value passed as 'version'
Dim nBufferSize As Long
Dim nUnused As Long
Dim lpBuffer As Long
Dim nVerMajor As Integer
Dim bBuffer() As Byte

Const sDLLFile As String = "shell32.dl l"

nBufferSize = GetFileVersionI nfoSize(sDLLFil e, nUnused)

If nBufferSize > 0 Then

ReDim bBuffer(nBuffer Size - 1) As Byte

Call GetFileVersionI nfo(sDLLFile, 0&, nBufferSize, bBuffer(0))

If VerQueryValue(b Buffer(0), "\", lpBuffer, nUnused) = 1 Then

CopyMemory nVerMajor, ByVal lpBuffer + 10, 2

IsShellVersion = nVerMajor >= Version

End If 'VerQueryValue
End If 'nBufferSize

End Function
' Code Start
'************** *************** *********

Copy and paste the code above into a module then call the BrowseFolder
function

Sample call:-

Dim strFolder as String

strFolder = BrowseFolder("F ind the Folder", "c:\program files")


Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3646
by: Kali K E | last post by:
Hi, I could not understand how I can do the following things in Python. Please help me. 1. First I have to find the current directory from where the script is invoked. 2. Next I have to form a directory structure there. If the current directory in step 1 is /home/mylogin, then from there I have to build a directory structure like /home/mylogin/result
0
1577
by: Bill | last post by:
I created a very simple DB with several forms and tables in chinese version of Access XP running in Chinese Win XP. Now I try to run the same DB in English version of Access XP running in English Win XP. The DB opens just find excpet all buttons or event on froms I click or do it gives me the following error. ______________ The expression On Click you entered as the event property setting produced the following error: A problem...
3
5728
by: Steve | last post by:
Recently due to viruses I had to wipe my harddrive and reload everything. Now, in AccessXP(2000 and XP mode) all new reports and all reports in existing databases open in Fit to Page rather than 100% like they use to. I also have Access97 and 2000 installed and all reports in both of these open at 100%. In fact, any report that I open in Access2000 will open at 100% but when I open the same reports in AccessXP 2000 mode, they open Fit to...
0
1329
by: Bob Hynes | last post by:
Hi All, In one of my Access97 db applications I created a report which I output to a RichTextFormat file attach it to an Email and send it out, that has worked just fine for a couple of years now. My company is in the midst of migrating to AccessXP. I loaded my Access97 application in AccessXP and converted it. The user who generates the report now has AccessXP and when she runs the process the format of the outputted RTF is messed up;...
1
1794
by: Locke Nash Cole | last post by:
I'm making a utility similar to MSConfig, I've found it easy enough to obtain the startup items from the registry for the current user and local machine... but what about the Startup folder on the Start Menu? I've found there are 2 system variables that could help me but.. what is the proper way to get these locations? And be win95/98/me/nt/2k/xp compatable? ALLUSERPROFILE=C:\Documents And Settings\All Users USERPROFILE=C:\Documents...
4
8412
by: John | last post by:
Hi I need to get the signature folder for the current folder such as; "F:\Documents and Settings\Dave\Application Data\Microsoft\Signatures\" except that instead of Dave I need the correct name for the current user, s that my code works generically regardless of who is logged in. Is there a way to do that? Thanks
1
3615
by: Simon | last post by:
Dear Access friends, How can I load a string with his own folder address. The following code addressed to the system folder of MS programs.
1
5773
by: mikebian | last post by:
I created a db that houses info about pictures that were scanned into the PC. The pictures are stored on the file system. I have a form coded so that it shows thumbnails of the images, which are stored in a directory under where the Access .mdb file is. For instance, in c: \MontvillePics, there exists MontvillePics.mdb. Then under c: \MontvillePics\pics are the actual .jpg files. Right now, I have the paths hard coded with those...
5
2142
by: bobh | last post by:
HI, I understand AccessXP file size has a 2 gig limit but I trying to understand the following I have a tab delimited data file that is 1.3 gigs big and I try to import it into an empty AccessXP database and it starts to import then stops, I look at the database size and it shows 1.99 gigs. AccessXP blots to almost twice the size of the import file??? is that
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.