GGill said:
In my table the field name is 'NameOfFile' . Basically data looks like this,
'C:\Folder\Data\5-22-06 this month.txt'.
I need get some portion of this data, only date, for exmple '5-22-06'.
This is only removes everything after date,
but also i need to remove everything after '\'.
Left([FILENAME],Len([FILENAME])-15)
Thank you for helping me.
This function should work in all cases. Put it in a standard module and
call it from your query as SELECT GetFilePart(MyField). (Watch out for
line wrapping.)
Public Function GetFilePart(FromPath As String) As String
' returns the first token following the last "\" (if any)
' as delimited by spaces
Dim BackSlash As Long
Dim FirstSpace As Long
GetFilePart = FromPath
BackSlash = InStrRev(FromPath, "\")
FirstSpace = InStr(BackSlash + 1, FromPath, " ") - BackSlash
Select Case BackSlash
Case Is = Len(FromPath)
' nothing follows BackSlash; no file specified
GetFilePart = "<not specified>"
Case Is > 0:
' we have a BackSlash
If FirstSpace > 0 Then
' ... and a space: this is well-formed
GetFilePart = Mid(FromPath, BackSlash + 1, FirstSpace - 1)
Else
' we have BackSlash, but no space
GetFilePart = Mid(FromPath, BackSlash + 1)
End If
Case 0:
' no BackSlash
If FirstSpace > 0 Then
' ... but a space: this is still legit
GetFilePart = Left(FromPath, FirstSpace - 1)
End If
End Select
End Function