Browse to file, dislpay JUST its name, open it?

G

Guest

Hi all,

I'm using the code from mvps.org

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

to get the browsing to work, and it works great. I can assign the path to a
text box, but I want just the file name (if possible).

I also want to be able to activate that file (with a command button) like
you double clicked it in windows explorer. I tried
Application.FollowHyperlink (Me.FilePathTextBox) but that doesn't work. Any
ideas?

TIA

Aaron G
Philadelphia, PA
 
D

Dirk Goldgar

Aaron G said:
Hi all,

I'm using the code from mvps.org

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

to get the browsing to work, and it works great. I can assign the
path to a text box, but I want just the file name (if possible).

I also want to be able to activate that file (with a command button)
like you double clicked it in windows explorer. I tried
Application.FollowHyperlink (Me.FilePathTextBox) but that doesn't
work. Any ideas?

If it's an existing file, you can easily get just the name into a text
box by using the Dir function on the full path; e.g,

Me!txtFileName = Dir(Me!txtFilePath)

However, to open it using FollowHyperlink, you'll need to pass the full
path. FollowHyperlink should work for that; in what way are you
finding that it "doesn't work"? Alternatively, you can call the Windows
ShellExecute API function using the code at:

http://www.mvps.org/access/api/api0018.htm
API: Start an app with ShellExecute

But as I said, FollowHyperlink ought to work, at least with most files,
provided you pass it the full path.

Note that, if the file doesn't exist, you can't use the Dir function to
extract the file name from the path. In that case, you have to actually
parse out the name using string-handling functions; or else create a
FileSystemObject and use its methods to return the name.
 
G

Guest

Hi,
use the Right and Instr function to retrieve just the filename up to the
first "\" from the right. The followhyperlink method should work, but try:

Application.FollowHyperlink Me.FilePathTextBox

HTH
Good luck
 
G

Guest

freakazeud,

I thought it might have something to do with RIGHT, but I've never used
INSTR before. Can you give this to me in a generic example? Thanks!

Oh, and removing the "()" seemed to do the trick for the followhyperlink.

Aaron G
Philadelphia, PA
 
G

Guest

Dirk,

The "Dir" solution worked perfectly! Thanks!

As for opening the file, all I had to do was to remove the parenthesis and
that worked fine as well.

Thanks again!

Aaron G
Philadelphia, PA
 
G

Guest

freakazeud,

Disregard my previous post. I'm using Dirk's solution. Thanks for all your
help.

Aaron G
Philadelphia, PA
 
G

Guest

yes that would work as well.
Glad you got it sorted out.
Good luck on future projects!
 

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