Open folder view in explorer by button

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
 
D

Dirk Goldgar

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

Blakey300

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

Dirk Goldgar

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top