I have a table where I use a field that is a hyperlink to hold a file name. The user gets an open dialog box to pick the file to use. That works fine. Then I want to strip the path and the file extension off to store in another field. It kind of works. It strips the path, but does not work for the file extension, because Access thinks the string is 196 characters long, way longer that it really is. What am I doing wrong? (Same results in Access 2003 and 2010). P.S. I can not find any documentation on GetOpenFileName, either.
code follows:
ReturnValue = GetOpenFileName(MyFile)
If ReturnValue = 0 Then
MsgBox "Cancel Button was pressed"
Else
path = "#..\" & Mid(MyFile.lpstrFile, 33) & "#"
pos = InStrRev(MyFile.lpstrFile, "\")
newName = Mid(MyFile.lpstrFile, pos + 1)
theLen = Len(newName)
RecipeName = newName
RecipeName = Mid(RecipeName, 1, theLen - 4)
End If
code follows:
ReturnValue = GetOpenFileName(MyFile)
If ReturnValue = 0 Then
MsgBox "Cancel Button was pressed"
Else
path = "#..\" & Mid(MyFile.lpstrFile, 33) & "#"
pos = InStrRev(MyFile.lpstrFile, "\")
newName = Mid(MyFile.lpstrFile, pos + 1)
theLen = Len(newName)
RecipeName = newName
RecipeName = Mid(RecipeName, 1, theLen - 4)
End If