Command to Open Folder Using File Path Link (1 Viewer)

cmcd29

New member
Local time
Today, 10:51
Joined
Jan 27, 2014
Messages
5
Hi I need help with creating a command to open a folder based on a file path.

I have a table with a calculated field which gives me the file path where I can find an employees training certs.

Example:
"C:\Field service\Training\Certificates\" & [Last Name] & " " & [First Name]

Separate to this I have a form which displays the file path (corresponding to the employee selected) in a text box.
Example:
C:\Field service\Training\Certificates\Smith John
[when John Smith's record is open]

I'm looking for a way to set up a command button which will open the folder (using the text box info) in a separate folder browser window.

If it is also possible to incorporate an error message if no file exists for a pathway that would be very helpful.

I have tried several different methods of getting this to work but with no luck yet. Any help would be greatly appreciated!

Thanks in advance!
cmcd
 

Trevor G

Registered User.
Local time
Today, 10:51
Joined
Oct 1, 2009
Messages
2,341
Welcome to the Forum,

Here is the first part of the code you need. You would have to alter the textbox name to the field name you are using on the form.

Private Sub Command0_Click()
Dim ProjPath
ProjPath = txtFilePath 'Change to the text box name
Shell "C:\WINDOWS\explorer.exe """ & ProjPath & "", vbNormalFocus
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:51
Joined
May 7, 2009
Messages
19,175
also:

application.FollowHyperlink strPath
 

cmcd29

New member
Local time
Today, 10:51
Joined
Jan 27, 2014
Messages
5
Thank you so much for such a quick response.

Trevor G your code worked beautifully! Do you happen to know a way to also input a pop up error message if a folder cannot be found? For instance if we have a record for an employee but no folder has been created yet?

Thanks again,
cmcd
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:51
Joined
May 7, 2009
Messages
19,175
use Dir

if Len(Dir(strPath))=0 then
msgbox "folder does not exists!"
else
' do something
end if
 

cmcd29

New member
Local time
Today, 10:51
Joined
Jan 27, 2014
Messages
5
Thank you arnelgp - that solved my second question. Many thanks :)
 

Users who are viewing this thread

Top Bottom