Access 2007-2013 Access 2000-2003 Seminars Tips & Tricks Access Forum Course Index Insider Circle

 Tutorials   News   Tips   Templates   Forums   Help   Logon   Order More... What's New? Tips & Tricks Access Index Access Tips Excel Index Excel Tips Waiting List

 Access   Excel   Word   Windows   FrontPage   Hardware   Misc

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

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

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:

 You may want to read these articles from the 599CD News:
 5/14/2013 Access Tip: Many-to-Many Relationships 5/14/2013 Access Expert 5 Handbook Ready 5/10/2013 Access Tip: Email Using Outlook 5/10/2013 Microsoft Access Expert 5 5/2/2013 Access Amort Handbook 4/29/2013 Microsoft Access Expert 4 4/28/2013 Access Tip: Toggle Button Colors 4/27/2013 Access Expert 4 4/23/2013 New Access Tip: Conditional Format Expression 4/15/2013 New Access Tip: Grid Lines v. Dots

Learn

 Microsoft Access index Microsoft Excel index Microsoft Word index Microsoft Windows index Microsoft PowerPoint index Adobe Photoshop index Visual Basic index Active Server Pages index Online Seminars More...
Customers

Online Theater
Insider Circle
Info

Latest News
New Releases
User Forums
Tips & Tricks
Search Our Site
Waiting List
Production Schedule
Help

Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services

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
Contact

Live Chat
General Contact Info
Support Policy
Contact Form
Email Us