trim function

  • Thread starter Thread starter stumpy
  • Start date Start date
S

stumpy

In acc2007 Is it possible to trim an image location when it could be placed
anywhere on the C: drive, trimming to the last \ in the address.

C:\Users\Rob\Pictures\Customxp R.png trim to Customxp.png
C:\Users\Rob\Downloads\Icons\cabriolet.jpg trim to cabriolet.jpg

Any guidance is appreciated.
 
You can either take a look at the InStrRev function, and get the location of
the last "\", and then use the Right() function to return just that portion
of the code

Or, you can use the Split function, put the string into an array using "\"
as a delimeter, and read the upper bound of the array to retrieve your
filename:

Dim x As Variant, f As String
x = Split("C:\ThisFolder\ThisFile.png", "\")
f = UBound(x)
Debug.Print f

hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Public Function GetFileFromPath(sPath As String) As String
GetFileFromPath = Right(sPath, Len(sPath) - InStrRev(sPath, "\"))
End Function


I had to check the syntax of InStrRev, haven't used it in a while.


Public Function GetFileFromPath(sPath As String) As String
Dim x As Variant
x = Split(sPath, "\")
GetFileFromPath = x(UBound(x))
End Function

that's the correct way to use the split method...

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Back
Top