Open folder view in explorer by button

  • Thread starter Thread starter Blakey300
  • Start date Start date
B

Blakey300

Hi

I am using Access 2007

I would like a button on my form that will open windows explorer to the
correct folder for the selected record.

the file path would be this:

=DLookup("[StudentFileLocation]","file locations") & [LastName] & ", " &
[FirstName]

Many tanks

Dave
 
Blakey300 said:
Hi

I am using Access 2007

I would like a button on my form that will open windows explorer to the
correct folder for the selected record.

the file path would be this:

=DLookup("[StudentFileLocation]","file locations") & [LastName] & ", " &
[FirstName]

Many tanks

Dave


If your database is in a trusted location, you should be able to use code
like this for your button:

'----- start of example code -----
Private Sub cmdExploreFolder_Click()

Shell _
"explorer.exe " & _
DLookup("[StudentFileLocation]","file locations") & _
[LastName] & ", " & [FirstName], _
vbNormalFocus

End Sub
'----- end of example code -----

Note, though, that Shell is a restricted function and you may need to do
something about trust settings or Jet sandbox mode to allow its use. I'm
not sure about that, and can't test it at the moment.
 
Hi Dirk

Tanks for your speedy reply

all works great except it does not work with the comma between the quoation
marks (It dosen't mind the spaces)

can you think of anyway round this (Wilst keeping the comma)

Regards

Dave

Dirk Goldgar said:
Blakey300 said:
Hi

I am using Access 2007

I would like a button on my form that will open windows explorer to the
correct folder for the selected record.

the file path would be this:

=DLookup("[StudentFileLocation]","file locations") & [LastName] & ", " &
[FirstName]

Many tanks

Dave


If your database is in a trusted location, you should be able to use code
like this for your button:

'----- start of example code -----
Private Sub cmdExploreFolder_Click()

Shell _
"explorer.exe " & _
DLookup("[StudentFileLocation]","file locations") & _
[LastName] & ", " & [FirstName], _
vbNormalFocus

End Sub
'----- end of example code -----

Note, though, that Shell is a restricted function and you may need to do
something about trust settings or Jet sandbox mode to allow its use. I'm
not sure about that, and can't test it at the moment.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Blakey300 said:
Hi Dirk

Tanks for your speedy reply

all works great except it does not work with the comma between the
quoation
marks (It dosen't mind the spaces)

can you think of anyway round this (Wilst keeping the comma)

Try this:

Shell _
"explorer.exe " & Chr(34) & _
DLookup("[StudentFileLocation]","file locations") & _
[LastName] & ", " & [FirstName] & _
Chr(34), _
vbNormalFocus
 
Back
Top