Strip Path Info From Field Data

G

Guest

I want the hyperlink address enetred into a field (LocalScanLink) to populate
a second field (FielName) with JUST the filename and it's extension, nothing
else. I finally got it to do this whereby the FileName field did not conatin
the hyperlink parts #...# in the field. However, if I insert a hyperlink that
is outside of the current directory of the db, or within the same directory
but in sub-directpry, the path is being dispalyed in the filename field
(X:/myfolder/etc.) Is there any way that I can strip the path from being
displayed as well? This is imperative that only the filename itself be
dispalyed in the FileName field. The code I have is:

If Len(Me!LocalScanLink & "") > 0 Then
Me!FileName = HyperlinkPart(Me!LocalScanLink, acAddress)
Else
Me!FileName = Null
End If

Please note I also tryed AcDisplayText in the above code and same probelm.
Thanks.
 
G

Graham Mandeno

Provided the file exists, you can use the Dir function to return only the
file name:
Dir("X:/myfolder/myfile.doc")
returns
myfile.doc

If you want to be more general, you can use the InStrRev function to find
the position of the last backslash and use the Mid function to return the
string after that point:
Mid( strPath, InStrRev( strPath, "\" ) + 1 )
 
G

Guest

Thanks Graham. The file location will change from user to user so I want to
strip the complete path. I tried your code but it comes up saying that the
filename field cannot accept zero length string. I changed this but still no
help. It must be in the syntax. Can you tell me the syntax on the following
code part?

If Len(Me!LocalScanLink & "") > 0 Then
Me!FileName = HyperlinkPart(Me!LocalScanLink, acAddress)
Me!FileName = Mid(strPath, InStrRev(strPath, "\") + 1)

Graham Mandeno said:
Provided the file exists, you can use the Dir function to return only the
file name:
Dir("X:/myfolder/myfile.doc")
returns
myfile.doc

If you want to be more general, you can use the InStrRev function to find
the position of the last backslash and use the Mid function to return the
string after that point:
Mid( strPath, InStrRev( strPath, "\" ) + 1 )

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

MBoozer said:
I want the hyperlink address enetred into a field (LocalScanLink) to
populate
a second field (FielName) with JUST the filename and it's extension,
nothing
else. I finally got it to do this whereby the FileName field did not
conatin
the hyperlink parts #...# in the field. However, if I insert a hyperlink
that
is outside of the current directory of the db, or within the same
directory
but in sub-directpry, the path is being dispalyed in the filename field
(X:/myfolder/etc.) Is there any way that I can strip the path from being
displayed as well? This is imperative that only the filename itself be
dispalyed in the FileName field. The code I have is:

If Len(Me!LocalScanLink & "") > 0 Then
Me!FileName = HyperlinkPart(Me!LocalScanLink, acAddress)
Else
Me!FileName = Null
End If

Please note I also tryed AcDisplayText in the above code and same probelm.
Thanks.
 
G

Graham Mandeno

Did you declare strPath as a string variable? You're not assigning any
value to it, so it will be an empty string.

Try this:
Dim strPath As String
strPath = HyperlinkPart(Me!LocalScanLink, acAddress)
If Len(strPath) > 0 Then
Me!FileName = Mid(strPath, InStrRev(strPath, "\") + 1)
End If
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


MBoozer said:
Thanks Graham. The file location will change from user to user so I want
to
strip the complete path. I tried your code but it comes up saying that the
filename field cannot accept zero length string. I changed this but still
no
help. It must be in the syntax. Can you tell me the syntax on the
following
code part?

If Len(Me!LocalScanLink & "") > 0 Then
Me!FileName = HyperlinkPart(Me!LocalScanLink, acAddress)
Me!FileName = Mid(strPath, InStrRev(strPath, "\") + 1)

Graham Mandeno said:
Provided the file exists, you can use the Dir function to return only the
file name:
Dir("X:/myfolder/myfile.doc")
returns
myfile.doc

If you want to be more general, you can use the InStrRev function to find
the position of the last backslash and use the Mid function to return the
string after that point:
Mid( strPath, InStrRev( strPath, "\" ) + 1 )

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

MBoozer said:
I want the hyperlink address enetred into a field (LocalScanLink) to
populate
a second field (FielName) with JUST the filename and it's extension,
nothing
else. I finally got it to do this whereby the FileName field did not
conatin
the hyperlink parts #...# in the field. However, if I insert a
hyperlink
that
is outside of the current directory of the db, or within the same
directory
but in sub-directpry, the path is being dispalyed in the filename field
(X:/myfolder/etc.) Is there any way that I can strip the path from
being
displayed as well? This is imperative that only the filename itself be
dispalyed in the FileName field. The code I have is:

If Len(Me!LocalScanLink & "") > 0 Then
Me!FileName = HyperlinkPart(Me!LocalScanLink, acAddress)
Else
Me!FileName = Null
End If

Please note I also tryed AcDisplayText in the above code and same
probelm.
Thanks.
 
G

Guest

I tried the code and although it produces no errors now, it still returns the
path (../MSDS.PDF). I took a look at MS VBA Guide but way too complicated for
me. I understand the concept but know nothing on the syntax. I pasted the
code I am using as:

Dim strPath As String
strPath = HyperlinkPart(Me!LocalScanLink, acAddress)
If Len(strPath) > 0 Then
Me!FileName = Mid(strPath, InStrRev(strPath, "\") + 1)
End If

Graham Mandeno said:
Did you declare strPath as a string variable? You're not assigning any
value to it, so it will be an empty string.

Try this:
Dim strPath As String
strPath = HyperlinkPart(Me!LocalScanLink, acAddress)
If Len(strPath) > 0 Then
Me!FileName = Mid(strPath, InStrRev(strPath, "\") + 1)
End If
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


MBoozer said:
Thanks Graham. The file location will change from user to user so I want
to
strip the complete path. I tried your code but it comes up saying that the
filename field cannot accept zero length string. I changed this but still
no
help. It must be in the syntax. Can you tell me the syntax on the
following
code part?

If Len(Me!LocalScanLink & "") > 0 Then
Me!FileName = HyperlinkPart(Me!LocalScanLink, acAddress)
Me!FileName = Mid(strPath, InStrRev(strPath, "\") + 1)

Graham Mandeno said:
Provided the file exists, you can use the Dir function to return only the
file name:
Dir("X:/myfolder/myfile.doc")
returns
myfile.doc

If you want to be more general, you can use the InStrRev function to find
the position of the last backslash and use the Mid function to return the
string after that point:
Mid( strPath, InStrRev( strPath, "\" ) + 1 )

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I want the hyperlink address enetred into a field (LocalScanLink) to
populate
a second field (FielName) with JUST the filename and it's extension,
nothing
else. I finally got it to do this whereby the FileName field did not
conatin
the hyperlink parts #...# in the field. However, if I insert a
hyperlink
that
is outside of the current directory of the db, or within the same
directory
but in sub-directpry, the path is being dispalyed in the filename field
(X:/myfolder/etc.) Is there any way that I can strip the path from
being
displayed as well? This is imperative that only the filename itself be
dispalyed in the FileName field. The code I have is:

If Len(Me!LocalScanLink & "") > 0 Then
Me!FileName = HyperlinkPart(Me!LocalScanLink, acAddress)
Else
Me!FileName = Null
End If

Please note I also tryed AcDisplayText in the above code and same
probelm.
Thanks.
 
G

Guest

I got it Graham! The "\" in the code needs to be "/". Although the insert
file dialog box shows the path as ..\whatever, the path once inserted looks
like .../whatever. Changed the slash direction and it works beauuuutifulllll.
Thanks a million from Wisconsin USA.

Mike
 

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