Using API GetOpenFile varDirectory parameter

paulmcneil
paulmcneil used Ask the Experts™
on
How do pass the varDirectory parameter to the API GetOpenFile function so that the default directory is My computer? Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
Well .... this is the Target for a shortcut I have on the destop to open to My Computer:


%SystemRoot%\explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}

If that helps ?

mx
Top Expert 2016

Commented:
that might not be possible...
this is close to that

    strStartDir = Environ("userProfile") & "\desktop"
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
This my help:

http://www.mvps.org/access/api/api0002.htm

Note the comment:

Stephen Lebans has added functionality to open the browse folder at a specific place.

which leads to:

http://www.lebans.com/callbackbrowser.htm

mx
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
Apparently the Lebans code will work - I just tried it - see image:
And his MDB is attached

mx
Capture1.gif
A2KCallBackBrowseVer4.zip
Top Expert 2016

Commented:
yeah, it does but it is not to get a file, will only allow you to select a folder...
Database Architect / Systems Analyst
Top Expert 2007
Commented:
Here you go.  If you make the Initial Directory:

"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"

Then it works.  I just tested it with this:

http://www.mvps.org/access/api/api0001.htm

Using the TestIt() function ... as such:

Function TestIt()
    Dim strFilter As String
    Dim lngFlags As Long
    strFilter = ahtAddFilterItem(strFilter, "Access Files (*.mda, *.mdb, *.mde, *.accdb, *accde)", _
                    "*.MDA;*.MDB;*.MDE;*.ACCDB;*.ACCDE")
    strFilter = ahtAddFilterItem(strFilter, "dBASE Files (*.dbf)", "*.DBF")
    strFilter = ahtAddFilterItem(strFilter, "Text Files (*.txt)", "*.TXT")
    strFilter = ahtAddFilterItem(strFilter, "All Files (*.*)", "*.*")

    ' Uncomment this line to try the example
    ' allowing multiple file names:
    ' lngFlags = ahtOFN_ALLOWMULTISELECT Or ahtOFN_EXPLORER

    Dim result As Variant

    'result = ahtCommonFileOpenSave(InitialDir:="C:\", _
        Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, _
        DialogTitle:="Hello! Open Me!")
     Dim sMC As String: sMC = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
     
     result = ahtCommonFileOpenSave(InitialDir:=sMC, Filter:=strFilter, FilterIndex:=3, Flags:=lngFlags, DialogTitle:="Hello! Open Me!")
       
       

    If lngFlags And ahtOFN_ALLOWMULTISELECT Then
        If IsArray(result) Then
            Dim i As Integer
            For i = 0 To UBound(result)
                MsgBox result(i)
            Next i
        Else
            MsgBox result
        End If
    Else
        MsgBox result
    End If

    ' Since you passed in a variable for lngFlags,
    ' the function places the output flags value in the variable.
    Debug.Print Hex(lngFlags)
End Function

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
So, now you have both ... File Browse opening to a specific Folder (my computer) and Folder Browse.

mx

Author

Commented:
Thanks to you both. However, I'm using Vista Ultimate and the code works without error, but still does not open the dialog at My Computer. Do you think the parameter
"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
needs adjusting for Vista Ultimate?
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
Well, I suppose so.  Would have been good to mention that up front.

According to this ... it's the same:

http://www.zdnet.com/blog/bott/the-ultimate-god-mode-list-39-secret-windows-7-shortcuts/1615?pg=3

mx

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
Then again, I'm not sure what that would change.

Here is more info on those Class IDs ... scroll down to "Before we go on, you need to understand what CLSID values are. These folders, like the Control Panel ..."

http://www.mastiland.com/forums/showthread.php?t=3331&mode=linear

You might nose around the Vista Registry and compare notes.  

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
Are you absolutely positive it's not working in Vista ?
What folder does it open to ?

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems Analyst
Top Expert 2007

Commented:
OK ... I just tried this in Windows 7 x64 ... and it in fact does open to 'Computer' ... which is the equivalent of My Computer in XP.  So, that tells me it did not change from XP to Vista.

Something else is going on with your system ...

mx

Author

Commented:
DatabaseMx,
It worked on the Windows XP pc where I'm developing, so you get the points! Thanks for the quick replies everybody.

Author

Commented:
Problem solved

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial