Opening a specific path defined in a text box using Windows Explorer

R

ronpassaro

Hi,

I've seen a lot of posts about how to open files from within Access as
well as opening folders in Windows Explorer. The latter can be done by:

Retval = Shell("explorer /e,/root, C:\My Dir", vbMaximizedFocus)

where "C:\My Dir" can be replaced with any path.

How can I use the same command and instead of putting the path in the
code itself, have the path be the contents of a text box. I would like
to do this in 2 ways:

If my textbox is called [PATH], and the value is:
N:/CP/23132/111/BOOKS, have the exact path open in explorer.

If [PATH] doesn't have the drive name and is only: CP/23132/111/BOOKS,
how do I add the drive name in the code so that it recognizes [PATH] to
be the rest of the directory, ie N:/[PATH]?

Thanks very much in advance,

-Ron
 
G

Guest

Dim stpath as string

If left(Me![path],3) = "N:\" then
stpath = Me![path]
else
stpath = "N:\" & Me![path]
end if

Retval = Shell("explorer /e,/root, " & stpath & ", vbMaximizedFocus)
 
R

ronpassaro

Thanks very much! This looks good, but the compiler is telling me that
the last line (starting with "Retval") is not formatted correctly. When
I try to correct it, explorer defaults to opening just the C: drive.

Thanks again,

-Ron
 
D

Douglas J Steele

It would have helped if you hadn't trimmed everything, making me go
searching for the thread... <g>

Try

Retval = Shell("explorer /e,/root, " & strPath, vbMaximizedFocus)
 
R

ronpassaro

Thanks Doug. That worked great. Not quite sure how to avoid trimming
the thread as I'm new to Google Groups. My apologies.

-Ron
 

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