two records, easy fix

binghamw

BingleyW
Local time
Today, 03:43
Joined
Apr 22, 2004
Messages
57
Hi -

I have two fields in my records. Filename and FilePathname
Both of them display the filename;

One displays the full pathname and the filename. The other one displays just the filename.

Example:

FilePathname: c:\temp\mydocuments\test.doc
Filename: test.doc


To select the FilePathname, the user can browse to the file and the pathname and filename are inserted automatically. Then I copy and paste the name of the file into the filename field.

I would like the filename to be an automatic entry (non-editable) FROM the FilePathname field but am not sure how to do this. How do you get it to display only PART of another record?


Any suggestions?
 
Try this...

Once you have the path, send it as the parameter to this function. Obviously, you may wish to add error handling and any other niceties as this is barebones... but it will return the file name from your path.

Public Function GetFileName(strPath As String) As String
Dim strChar As String
Dim intPathLength As Integer
Dim intStrPos As Integer
Dim intFileNameLength As Integer

strChar = "\"
intPathLength = Len(strPath)
intStrPos = InStrRev(strPath, strChar)
intFileNameLength = intPathLength - intStrPos
GetFileName = Right(strPath, intFileNameLength)

End Function

HTH :cool:
 
InStrRev()

I be darn - Never seen that. Cool, Thanks!

kh
 
Sam F - I'm not sure I understand it completely. Sent it as a parameter to this function? And where exactly do I paste that code? I'm a bit confused... sorry.


thanks for the reply!!
 
Let' s make sure I understand your requirement.

You have two fields, one of which contains the path to a file and includes the file name.

You want to extract only the file name from the path and have the file name appear in a field on your form.

You can do this by setting the Control Source on the file name field on the form to:

"=GetFileName([FilePathName])"

Or, you can add a calculated field in your underlying query, something like:

FileName: GetFileName([FilePathName])

and set the Control Source on your form to that calculated field in the query.
[I prefer this method]

Does this help?
 
Yes, you are correct [of the understanding].

I tried the first method and I end up with this in the filename textbox (on the form):

#Name?

I don't completely understand the second method.

I pasted it into the query (under the file field) and I couldn't save the query.
 
This should work...

The first solution works fine in my form... two fields, one bound to the full path [FullPathName], and the second is unbound and has a data source of "=GetName([FullPathName])"

OK, let's go with the second solution. Here is the underlying query:

SELECT
tblGetFileName.FullPathName
, GetName([FullPathName])

AS
FileName

FROM
tblGetFileName;

That second field is a calculated field and will supply only the file name.

I had to change the function a bit, name conflict, so here is the version that works with this query:

Public Function GetName(strPath As String) As String
Dim strChar As String
Dim intPathLength As Integer
Dim intStrPos As Integer
Dim intFileNameLength As Integer

strChar = "\"
intPathLength = Len(strPath)
intStrPos = InStrRev(strPath, strChar)
intFileNameLength = intPathLength - intStrPos
GetName = Right(strPath, intFileNameLength)
Debug.Print GetName

End Function

:D
 
Last edited:
hi i have a selfmade db just for this purpose.. i tried to upload it here but it is too large. please provide with you email so ican send it to you.
 

Users who are viewing this thread

Back
Top Bottom