Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
MS Access

Remove file extension

How to remove a file extension from a filename

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")

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

You may want to read these articles from the 599CD News:

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP