From: Mark Andrews on 14 May 2010 12:52 I am using this code to browse for a folder (just folders no files) in Access 2007. It works great, I just want one extra feature: - to supply a starting folder I found one example on stephen lebans site http://www.lebans.com/callbackbrowser.htm but it required the code to exist in the code behind the form. I use this on about 10 forms so would prefer something that I could place in just one module. Does anyone have a better solution? Thanks in advance, Mark -------------------------------- Option Compare Database Option Explicit Private Type BROWSEINFO hOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _ "SHGetPathFromIDListA" (ByVal pidl As Long, _ ByVal pszPath As String) As Long Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _ "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _ As Long Private Const BIF_RETURNONLYFSDIRS = &H1 Private Const BIF_NEWDIALOGSTYLE = &H40 Public Function BrowseFolder(szDialogTitle As String) As String Dim X As Long, bi As BROWSEINFO, dwIList As Long Dim szPath As String, wPos As Integer With bi .hOwner = hWndAccessApp .lpszTitle = szDialogTitle .ulFlags = BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE End With dwIList = SHBrowseForFolder(bi) szPath = Space$(512) X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath) If X Then wPos = InStr(szPath, Chr(0)) BrowseFolder = Left$(szPath, wPos - 1) Else BrowseFolder = vbNullString End If End Function ---------------------------------------- -- Mark Andrews RPT Software http://www.rptsoftware.com http://www.donationmanagementsoftware.com
From: Jörn Bosse on 14 May 2010 14:17 Hi, I would solve this with a Public Function in an extra module. Something like this Public Function DefaultPath() As String Const strDefaultpath As String = "C:\Program Files" DefaultPath = strDefaultpath End Function You can use this like this: Debug.Print DefaultPath Jörn
From: Mark Andrews on 14 May 2010 14:33 What? I'm looking for a way to supply a default folder to the Browse For Folder dialog when using it from VBA code. Example: A form has a field with a folder path, when clicking on a button the "Browse For Folder" dialog box displays and by default starts at the folder path I supply (based on this field on the form). Stephan Lebans code does exactly what I want I just don't like all the warnings about using it certain ways or the program will crash. Also don't like that the code must exist in the form class module instead of a normal module. Mark "Jörn Bosse" <JrnBosse(a)discussions.microsoft.com> wrote in message news:76E35220-E833-45D5-8FD5-BE39DCC3AAF0(a)microsoft.com... > Hi, > > I would solve this with a Public Function in an extra module. Something > like > this > > Public Function DefaultPath() As String > Const strDefaultpath As String = "C:\Program Files" > DefaultPath = strDefaultpath > End Function > > You can use this like this: > Debug.Print DefaultPath > > Jörn
From: Tom van Stiphout on 15 May 2010 00:09 On Fri, 14 May 2010 14:33:18 -0400, "Mark Andrews" <mandrews___NOSPAM___(a)rptsoftware.com> wrote: You wrote: Also don't like that the code must exist in the form class module instead of a normal module. I ask: why not? Aren't class modules full citizens in the Access world? That said, there certainly is a way to set a default folder. Check this out: http://msdn.microsoft.com/en-us/library/bb774065%28VS.85%29.aspx -Tom. Microsoft Access MVP >What? > >I'm looking for a way to supply a default folder to the Browse For Folder >dialog when using it from VBA code. > >Example: A form has a field with a folder path, when clicking on a button >the "Browse For Folder" dialog box displays and by default >starts at the folder path I supply (based on this field on the form). > >Stephan Lebans code does exactly what I want I just don't like all the >warnings about using it certain ways or the program will crash. >Also don't like that the code must exist in the form class module instead of >a normal module. > >Mark > >"J�rn Bosse" <JrnBosse(a)discussions.microsoft.com> wrote in message >news:76E35220-E833-45D5-8FD5-BE39DCC3AAF0(a)microsoft.com... >> Hi, >> >> I would solve this with a Public Function in an extra module. Something >> like >> this >> >> Public Function DefaultPath() As String >> Const strDefaultpath As String = "C:\Program Files" >> DefaultPath = strDefaultpath >> End Function >> >> You can use this like this: >> Debug.Print DefaultPath >> >> J�rn
From: Mark Andrews on 15 May 2010 08:33
Tom, Thanks for the info. I think I found two ways to do it: - the way you pointed out which you pass the root folder (however the downside is you lose the ability to browse around, you can only browse from that root folder down) However this way is supported. - Stephan lebans code (which does exactly what I want, shows entire tree but navigates to folder passed in) However downsides are that you need to duplicate code and put it in every form in which you want this functionality otherwise your program will crash. It looked like this was done about 7 years ago, so basically just wondered if any newer better ways were possible? I just didn't want to duplicate code in 10 forms and try not to use code that might cause crashes. If you know of any betters ways let me know, Thanks for your help, Mark "Tom van Stiphout" <tom7744.no.spam(a)cox.net> wrote in message news:be7su5lbiukgqoikq41q4j1tf5vsoe6e5s(a)4ax.com... > On Fri, 14 May 2010 14:33:18 -0400, "Mark Andrews" > <mandrews___NOSPAM___(a)rptsoftware.com> wrote: > > You wrote: > Also don't like that the code must exist in the form class module > instead of a normal module. > > I ask: why not? Aren't class modules full citizens in the Access > world? > > That said, there certainly is a way to set a default folder. Check > this out: > http://msdn.microsoft.com/en-us/library/bb774065%28VS.85%29.aspx > > -Tom. > Microsoft Access MVP > > > >>What? >> >>I'm looking for a way to supply a default folder to the Browse For Folder >>dialog when using it from VBA code. >> >>Example: A form has a field with a folder path, when clicking on a button >>the "Browse For Folder" dialog box displays and by default >>starts at the folder path I supply (based on this field on the form). >> >>Stephan Lebans code does exactly what I want I just don't like all the >>warnings about using it certain ways or the program will crash. >>Also don't like that the code must exist in the form class module instead >>of >>a normal module. >> >>Mark >> >>"J�rn Bosse" <JrnBosse(a)discussions.microsoft.com> wrote in message >>news:76E35220-E833-45D5-8FD5-BE39DCC3AAF0(a)microsoft.com... >>> Hi, >>> >>> I would solve this with a Public Function in an extra module. Something >>> like >>> this >>> >>> Public Function DefaultPath() As String >>> Const strDefaultpath As String = "C:\Program Files" >>> DefaultPath = strDefaultpath >>> End Function >>> >>> You can use this like this: >>> Debug.Print DefaultPath >>> >>> J�rn |