Solved

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

Posted on 2006-10-26
14
773 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 
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
 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

734 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