Solved

Access crashes when I use SHBrowseForFolder and pass in an incorrect PIDL

Posted on 2006-10-26
14
732 Views
Last Modified: 2012-06-22
When I open the SHBrowseForFolder window, I can pass in a PIDL that will be the top-level (root) folder for the Browse Window. But for some reason my PIDL is invalid (a day or two after setting it) and causes Access to crash. Am I using a wrong PIDL? Is it relative instead of absolute?

0
Comment
Question by:HKComputer
  • 6
  • 5
14 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17814682
What BROWSERINFO settings r u using?

ive never had a problem. The code I used is

    Dim tBI As BROWSEINFO
    Dim pIdl As Long


    tBI.lpszTitle = "Browse File"
    tBI.ulFlags = &H4000
    pIdl = SHBrowseForFolder(tBI)


0
 
LVL 4

Author Comment

by:HKComputer
ID: 17834486
Here's my code. I've disabled the feature that was giving me a problem. I never pass in lngPIDListOpen anymore because it sometimes crashes Access. It appears that an ItemIDList (or PIDL) is relative and might change. I don't even have to restart my computer to get it to crash.  I was using this same function to retrieve the PIDL and then store it in a field in tblSettings. Then I'd retrieve it with a DLookup (or tLookup, actually) and pass it into BrowseDirectory, and then Access would crash. The problem appears to occur after a couple days.

Public Function BrowseDirectory(Optional bleReturnString As Boolean = True, Optional strTitle As String, Optional lngPIDListOpen As Long = 0) As Variant
On Error GoTo Err_BrowseDirectory

    Dim objBrowseInfo As BROWSEINFO
    Dim lngPIDList As Long
    Dim strPath As String
   
    objBrowseInfo.lpszTitle = strTitle
    objBrowseInfo.pidlRoot = lngPIDListOpen
    objBrowseInfo.ulFlags = &H4000 + &H40
    lngPIDList = SHBrowseForFolder(objBrowseInfo)
   
   
    If lngPIDList = 0 Then Exit Function
    If bleReturnString = False Then
        BrowseDirectory = lngPIDList
        Exit Function
    End If
   
    'Get selected path from the id list, will rtn False if the id list can't be converted
    strPath = String$(260, 0) 'Initialize to a 260 character string
    SHGetPathFromIDList ByVal lngPIDList, ByVal strPath
   
    ' Display the path and the name of the selected folder
    BrowseDirectory = Left(strPath, InStr(strPath, vbNullChar) - 1)
   

Exit_BrowseDirectory:
    Exit Function

Err_BrowseDirectory:
    Call ErrorLog(Err.DESCRIPTION, Err.Number, "mdlPublicFunctions", "BrowseDirectory")
    Resume Exit_BrowseDirectory
   
End Function
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17931584
I'll make a request to delete and refund. -HK
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17933680
ok, one that slipped the net.

I took your code and cannot reproduce the problem

Are u passing any parameters when u call this func?
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17933754
I was using this same procedure to get a PIDL, then store it in my settings table. After keeping it a couple days, it caused the crashes.

Yes, when I call this function I do this:

Dim lngPIDL as Long, strFileName as String
lngPIDL = tLookup("PIDL", "tblSettings")
strFileName = BrowseDirectory(True, "Find Pictures", lngPIDL)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17933956
so I take it u only have one record in tblSettings and does the value of PIDL change?
can u give me the value u use?

R u using this to specify a starting location by any chance?

I suggest u use something like

SHGetPathFromIDList

to obtain it

You may be interested in the callback func I posted here
http://www.experts-exchange.com/Databases/MS_Access/Q_21910808.html

this allows u to specify a start dir, if thats what u are interested in
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17934014
Yep. I'm using it as a starting location.  And, right of hand, I don't have a number for you right now.

Why would you use SHGetPathFromIDList? You can't use a string path to specify a starting location, can you?

I see that you can using a path if you use the callback function, right?  What is a callback function? They are new to me.

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17934098
A callback function is like some executable code that u pass as an argument
so we pass in the function here

I dont think u can rely on storing the PIDL as this may vary - Im not sure as Ive never had any reason to keep these.
But u are right, u cannot use a string to specify a starting location. Why MS decided to make it so damn complicated, I dont know.

So way round this is to get the current PIDL from the specified directory, u then use this instead of the one stored in the table

The parameters to the callback function are standard parameters. U have to define these for all funcs
uMsg refers to an action, I dont know the full list though

Did my sample code work for you?

I wonder now if u store the path rather than PIDL in tblSettings, then use that (my example uses a variable called sStart)

0
 
LVL 4

Author Comment

by:HKComputer
ID: 17934163
I haven't tried your code yet, but it surely does look like a good solution. And I will be trying it.  I had even seen this callback idea before but it seemed way too complicated everywhere I read about it.

I think you are exactly correct. It is not reliable to store a PIDL in a table and expect it to be current.

I'll report back here on how it works for me.  -HK
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17934203
ok, no worries
its also bedtime for me
0
 
LVL 4

Author Comment

by:HKComputer
ID: 17943508
I think we can now resolve this one without closing it. Please hold off on the close request.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now