3 minutes
ago: Please note that the webserver will soon get its weekly reboot at 4:00 am Eastern Time. You may continue to use the site as normal, but you will be logged off at that time. You should be able to log right back on immediately, however. If you are in the process of placing an order, please make sure to complete it as quickly as possible, or come back after the reboot. Thank you. Sorry for any inconvenience.
Dismiss
In this example we will remove a file extension from filename using a few different functions.
We will use Left and InStrRev.
If we get the position of the last dot (.) in the Filename we can then use that to remove it from the whole string.
This will return where the dot (.) is so we need to remove that as well so that is why we minus 1 from that
value and now we can use the Left function to get just the File.
VBA
'Filename = "test.doc"
'12345678
'test.doc
Public Function GetFilename(Filename) As String
Dim File As String
Dim dotpos As Integer
dotpos = InStrRev(Filename, ".") '5
Dim JustFile As String
JustFile = Left(Filename, dotpos - 1) '5-1 = 4
'Join these together
File = Left(Filename, InStrRev(Filename, ".") - 1)
GetFilename = File
End Function
You could call this Function in a Query or a Form. =GetFilename("test.doc")