Get "folder path" from "file path"

mixup

Registered User.
Local time
Today, 14:33
Joined
Jul 29, 2005
Messages
34
After some help from one of the threads here I managed to install a Browse button in a form that inserts a file path to a text box. What I need is the folder path from that file path in another text box. For example if the file path is
C:\Documents and Settings\mixup\Sketches\owl.jpg

I would like to get either
C:\Documents and Settings\mixup\Sketches\
Or,
C:\Documents and Settings\mixup\Sketches
in my second text box.

I do not have much experience with Access; therefore please give a little detail on how to accomplish this.

Thanks.
 
Left(InString, InStrRev(InString, "\") - 1) gives you:

C:\Documents and Settings\mixup\Sketches

Left(InString, InStrRev(InString, "\")) gives you:

C:\Documents and Settings\mixup\Sketches\
 
Does this go to the Control Source of the text box?

Rural Guy:

Thanks for your reply. I need a little clarification.

I have one txt box field (Say, Text1)that contains the full path: C:\documents and settings\owner\photos\owl.jpg

If I want it in a different text box (Say, Text2), do I put:
=[Text1].Left(InString, InStrRev(InString, "\") - 1)
in the control source for Text 2? I tried that, and it is not registering.

Like I said, I am new to Access and I would appreciate If you could give me a little more detail.

Thanks.
 
Set Text2 Control Source to:

=Left(Text1, InStrRev(Text1, "\"))

OR

Left(Me.Text1, InStrRev(Me.Text1, "\"))

But I don't think you need the Me reference!
 
I tried both of those options. The first one, without "me" gives me an "Error" message in the text box. While the second one with the "me" reference does not work either, with a "Name#?" message in the text box when I go back to the form view from the design view.

Is there something that I am doing wrong?
 
I just tried the first option and it works properly. How about posting the exact Control Source that is giving you Error.
 
Rural Guy:

Thanks for your help. I dont know however what I was doing wrong before. As I was trying it one last time before sending you a part of the database, it worked! And it worked without the "Me" referenceThank you so much for the help.
 
You're welcome and thanks for posting back with your success.
 
mixup said:
After some help from one of the threads here I managed to install a Browse button in a form that inserts a file path to a text box. What I need is the folder path from that file path in another text box. For example if the file path is
C:\Documents and Settings\mixup\Sketches\owl.jpg

I would like to get either
C:\Documents and Settings\mixup\Sketches\
Or,
C:\Documents and Settings\mixup\Sketches
in my second text box.

I do not have much experience with Access; therefore please give a little detail on how to accomplish this.

Thanks.
If you were referrring to my Browsing sample then you could have used the ParseFileName() function I am using in the fFindOpenImportFile form in my Browse [Find a directory or file] sample. It would do what you wanted to extract the drive, path and file name all together and/or each part separately.
 
Ghudson: I was actually using a code from the Microsoft Knowledge Base for the Browse function. But you are right this (your code) actually combines two steps in to one. I am learning more about access from this forum than any book. Thanks to all of you.
 

Users who are viewing this thread

Back
Top Bottom