Solved

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

Posted on 2006-10-26
14
739 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

910 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

23 Experts available now in Live!

Get 1:1 Help Now