Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Remove Special Characters
William Dowler 
      
4 years ago
I asked one of my team to create the code to remove special characters from a ContractorName field before saving a .pdf file with the name based on the ContractorName (.pdf names can't include special characters).
I thought her one-line-of-code solution was elegant. I include it below in case it proves useful to anyone in the forum:
strContractor = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Me!CONTRACTORNAME, "/", ""), "\", ""), ":", ""), "*", ""), "|", ""), "<", ""), ">", ""), """", "")
Scott Axton  @Reply  
        
4 years ago
A little redundant but if it works...  Good job.

There is an example in the Code Vault - IsFound Any Char in String  that is a little more compact and you can also check things like upper and lower case etc.  Good for passwords as well.
Scott Axton  @Reply  
        
4 years ago
The video showing how that was created:  String Functions
William Dowler OP  @Reply  
      
4 years ago
Thanks Scott,
The main difference between the code you point to and ours is that we actually remove the special characters to enable the revised name to form part of the .pdf filename (along with a date/time stamp).
I can see the value in both methods though, depending on what the objective is.... Thanks again......
Dan Jackson  @Reply  
            
4 years ago
Hi William,

I use this code for my contact names. It essentially lists what IS allowed, rather than what isn't!

Is Not Null And Not Like "*[!-A-Z']*"

Breaking this down:
Is Not Null - Speaks for itself, can't be blank
*[!-A-Z']* - Put in here the characters you want to allow. I'm allowing A thru to Z, - and ' which allows for names like anne-marie and O'Sullivan.

That includes spaces and numbers too! I.E. no spaces and no numbers allowed. Just edit it to requirements
Scott Axton  @Reply  
        
4 years ago
William -
My bad I should have qualified my statement above a little better. The thing about the one line code you presented above will catch the first occurrence of any of the characters you have in your string then go on.  What happens if more than one of your disallowed characters are in your string?
The function I pointed you to above shows you how to loop through the whole string to ensure you don't have ANY of those characters.
What you do with those characters is up to you.

Dan Jackson just gave you a great example above on how to shorten down your code.
Dan Jackson  @Reply  
            
4 years ago
The only difference between the two codes is that Williams will automate the process after the name is entered whereas mine will actively stop the user from typing the name so they can't physically type the special characters
Scott Axton  @Reply  
        
4 years ago
True.  But what if it is not being typed in?  An import for instance.  That would cause errors instead of correcting the file name for the import.
William Dowler OP  @Reply  
      
4 years ago
Scott,
In this particular case it would be extremely unlikely for a ContractorName to contain more than one special character so the solution we implemented will work fine but I take your point, in a different scenario your method, or Dan's, would be the way to go with some modifications to remove the character(s) in question. We have situations where the ContractorName with a special character is valid (e.g. T/A Electrical, Inc.) so we have to modify the .pdf name and leave the Contractor name as entered.
Fascinating stuff though, (I love the different solutions that occur to different developers). Skinning a cat comes to mind. Lol
Richard Rost  @Reply  
          
4 years ago
What you want is Filter Characters

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 10:51:25 PM. PLT: 1s