[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1733
  • Last Modified:

Browse Folders in Access 2010

I've been using the Browse Folders API from the "Access Web" for several years (Access 2003 and 2007).  Now I've got a 2007 accdb that is being run in 2010 (64 bit) in a Windows 7 environment.  But when the BrowseFolders API is called, Access 2010 locks up and then shuts down.  

I've modified the original code as follows to account for the 64 bit processor, as indicated in several other posts on this site, but this has not helped.

#If Win64 = 1 Then
    Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias _
                "SHGetPathFromIDListA" (ByVal pidl As Long, _
                ByVal pszPath As String) As Long
               
    Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" Alias _
                "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
                As Long
#Else
    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
#End If
 
Any ideas how to resolve this?  

I've got a built-from-scratch BrowseFolders form that I created using a treeview control, which also works great in 2007, but when I try to open the form in 2010, it gives me an error message that says "there is no object in this control".  When I tried to add a new ActiveX treeview control to the form, I couldn't find the treeview in the list of ActiveX controls, so that one doesn't work in 2010 either.
0
Dale Fye
Asked:
Dale Fye
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Nick67Commented:
@fyed,

I think you'd best clarify the exact nature of your 64 bit environment.
I run 32 bit Office on Window 7 Ultimate 64 bit.
I don't need the PtrSafe part of the declarations and all my API code runs completely unchanged from my XP-32 bit /Access 2003 32-bit production code

You are running 64 bit Office on 64 bit Windows, correct?
0
 
rockiroadsCommented:
I have never used msaccess on a 64bit platform running 64bit office. I have ran 32bit office 2010 on 64bit Win7 and that works fine. (including your code). I realise that PtrSafe is needed to help run 32bit api's in 64bits but cannot shed any light on why it is misbehaving. Perhaps there is some corruption or conflict elsewhere.

Have you tried creating a new db, with just some test code for your shbrowser dialog? If that works then you know the issue cant be with this bit of code.

There is an alternative with works in 2007 32bit and I assume 64bit also since it requires a reference to the office object library/ It is not as sexy as shbrowserdialog but it requires no api declarations.


Dim fDialog As Office.FileDialog
Dim sFolder As String

Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
fDialog.Show
sFolder = fDialog.SelectedItems(1)

MsgBox "Selected folder is " & sFolder
0
 
rockiroadsCommented:
ok, just had a thought. What if you used the new datatypes? like LongPtr or LongLong ?

eg

    Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" Alias _
                "SHGetPathFromIDListA" (ByVal pidl As LongPtr, _
                ByVal pszPath As String) As LongPtr

the BROWSEINFO type would need changing also (example below is just one change)

  hOwner As LongPtr


so you would need to wrap that inside your IF also
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JezWaltersCommented:
Have you thought of using the Shell.BrowseForFolder method instead?

    http://msdn.microsoft.com/en-us/library/bb774065(v=vs.85).aspx
0
 
JezWaltersCommented:
This should give you the idea of how to invoke the Shell.BrowseForFolder method:
Option Explicit      ' Force explicit variable declaration
Option Compare Text  ' Perform case-insensitive comparisons

' See http://msdn.microsoft.com/en-us/library/bb774096(v=vs.85).aspx for other constants
Public Const ssfDESKTOP As Long = &H0

Public Function BrowseForFolder(pvarFolder As Variant) As Variant

    ' See http://msdn.microsoft.com/en-us/library/bb773205(v=vs.85).aspx for other constants
    Const BIF_STATUSTEXT As Long = &H4
    Const BIF_EDITBOX As Long = &H10
    Const BIF_VALIDATE As Long = &H20
    Const BIF_NEWDIALOGSTYLE As Long = &H40

    Dim shlShell As Object       ' Actually Shell32.Shell
    Dim fldFolder As Object      ' Actually Shell32.Folder
    Dim fdiFolderItem As Object  ' Actually Shell32.FolderItem

    Set shlShell = CreateObject("Shell.Application")  ' Or  New Shell32.Shell
    Set fldFolder = shlShell.BrowseForFolder(hWndAccessApp, _
                                             "Select folder", _
                                             BIF_STATUSTEXT + BIF_EDITBOX + BIF_VALIDATE + BIF_NEWDIALOGSTYLE, _
                                             pvarFolder)
    If Not fldFolder Is Nothing Then
        Set fdiFolderItem = fldFolder.Self

        Debug.Print fdiFolderItem.Path

        Set fdiFolderItem = Nothing
    End If

    Set fldFolder = Nothing
    Set shlShell = Nothing

End Function

Public Sub Test()

    BrowseForFolder ssfDESKTOP  ' Or "C:\Temp" etc.

End Sub

Open in new window

0
 
Dale FyeAuthor Commented:
@nick/rocki

My client has a number of Win7 (64 bit) computers and recently purchased some BI software that apparently requires A2010 (64 bit), so I downloaded the 64 bit A2010 and installed it on my new laptop.  Most of their computers are XP or Win7 running 32 bit Access 2007, so my primary development environment for them is 32 bit 2007.  But in an effort to avoid having two separate versions of the application, have used the conditional compilation for a couple of the other API calls, and that has worked well.  

I've used the fileDialog in the past, but stopped using it after finding the API call.  I'll take a look at modifying some of the other parameters in that API.

@Jez:

Was not aware of the shell.BrowseForFolder option.  I'll take a look at it as well.
0
 
Nick67Commented:
@fyed

I am afraid I don't have much to teach here, just a lot to learn
can you post some resources on <conditional compilation>

This is a pin that all of us are going to have to pull some day.
May aw well start getting my feet wet early
0
 
Nick67Commented:
@fyed
Thank you for putting in the phrase <conditional compilation>
There's stuff about it here
http://office.microsoft.com/en-us/access-help/HV080755465.aspx

One of the biggest PITA's I encounter in a mixed environment is FilterOnLoad.
2003 reopens forms with the filter off.  2007/2010 not so much.
I've handled it by putting Me.filter = "" in the close event of every form because, while I could test for version, I didn't know how to get the debugger not to hate properties that didn't exist downlevel.
Thnak you!
0
 
Nick67Commented:
Reading your original post again.
<I couldn't find the treeview in the list of ActiveX controls>

MS deprecated the Calendar control--which was a PITA to me.
I got it working in Access 2010 with steps noted here
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_26992166.html?cid=1572#a35728584

Perhaps the same attack may work for this?
Find and copy the dll, register it, and save out the registry keys from a system after you get it going to make future deployment simple?
0
 
JezWaltersCommented:
You'll have to confirm this for yourself, but I reckon you'll find that the Shell.BrowseForFolder method (in the Microsoft Shell Controls And Automation library, SHELL32.dll) works unaltered for all Access/Windows versions.
0
 
Dale FyeAuthor Commented:
JezWalters,

That worked great, in both 2007 and 2010, and avoids the reference necessary for the fileDialog method
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now