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

   
 

Break Up a Text String in Microsoft Access

Using the InStr Function and String Manipulation

Q: I have an Excel spreadsheet where a single column can sometimes have several different types of data in it. I need to be able to separate those pieces of data out into different fields. How can I do it?

A: Here is the sample data that the customer sent me:

As you can see, the Price field contains all kinds of different bits of data... sometimes a single price like $450,000, sometimes a price per square foot, sometimes a range of prices, and sometimes just "See Agent". We need to be able to break all of these down - and even separate out the minimum and maximum values for those items that give the range of prices so the data looks like this:

How do I do this? Well, the key is to know all of your String Manipulation Functions and to use them properly. In this lesson I needed to use all of these functions:

In addition to:

Here is a video tutorial that shows everything I did, step-by-step, and the sample database that contains all of the query code:

 Click here to view the video
   

 Click here for Sample Database File  ZIP file, 16k, Access 2003 Format

Now, this video goes at a pretty fast clip. It's designed for people who have already taken all of the classes listed above (at least through Access 308). If you have not, then I suggest you take those classes first, and then try to tackle this one!


ADDENDUM (7/24/09): Travis asks: How do I convert this date from 1090621 into 6/21/2009?

Answer: You'll need to learn the string manipulation functions: left, right, mid, from above.

Now, since the first three digits are 109, I'm assuming this was from a legacy (pre-Y2K) database. This is going to make it even more fun. You have to change the way the month and year are calculated based on the length of the whole date. Dates from 1900 to 1999 are 6-digits. Days from 2000 to now are 7 digits.

I would start by breaking this down into different query fields:

MyDay: right(D,2)
MyMonth: IIF(Len(D)=6,mid(D,3,2),mid(D,4,2))
MyYear: IIF(Len(D)=6,left(D,2),left(D,3))
MyYear2: CInt(MyYear) + 1900
NewDate: DateSerial(MyYear2,MyMonth,MyDay)

That last one should be what you're looking for.


 


ADDENDUM (7/25/09): This seems to be a popular topic lately. Here's another one. Scott says he has a table with values that look like this:

He needs to separate out that code - the [a] or [1] - from the rest of the name. Again, our string functions come to the rescue. Here's another video:

 Click here to view the video


 


By Richard Rost   Richard Rost on Facebook Richard Rost on Twitter Richard Rost on Google Plus Richard Rost on LinkedIn Email Richard Rost

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