473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Parse fields in table

Howdy!
I've got a table with some contact information.
uid, emailaddy, username

The user name data is inconsistent.... some names are as Bill Jones, some are B.Jones and some are the email address as well.

I need to parse through the fields and where there is a space between the names, break them out into two separate fields.

I'm stumped!

Any direction would be greatly appreaciated!
Thanks!
Jan 5 '09 #1
6 4470
ADezii
8,834 Expert 8TB
@artemetis
Assuming your Table Name is tblNames, I know not very original, the following code will parse any Value in the userName Field that has a space in it, and Update two Fields named First and Last. But first:
  1. If your Table Name is not tblNames, change it in the code.
  2. Add 2 Fields to your Table and name them First and Last. Should you name them differently, adjust the code accordingly.
  3. Download the Attachment to get a visual cue as to what is going on.
  4. Any questions concerning the code, feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rstParseNames As DAO.Recordset
  3.  
  4. Set MyDB = CurrentDb
  5. Set rstParseNames = MyDB.OpenRecordset("tblNames", dbOpenDynaset)
  6.  
  7. With rstParseNames
  8.   If Not .BOF And Not .EOF Then     'has at least 1 Record
  9.     Do While Not .EOF
  10.       If InStr(![UserName], " ") > 0 Then
  11.         .Edit
  12.           ![First] = Left$(![UserName], InStr(![UserName], " ") - 1)
  13.           ![Last] = Mid$(![UserName], InStr(![UserName], " ") + 1)
  14.         .Update
  15.       End If
  16.       .MoveNext
  17.     Loop
  18.   Else
  19.     'fall through
  20.   End If
  21. End With
  22.  
  23. rstParseNames.Close
  24. Set rstParseNames = Nothing
Jan 6 '09 #2
Thanks!

As it turns out, the table is slightly more complicated.

There is not only first and last name in there, but Middle initials, and some other crap, which at this point, i'm thinking is impossible to clean up.
Jan 6 '09 #3
missinglinq
3,532 Expert 2GB
We see questions like this, both here and elsewhere, over and over and over again! If the original data is as simple as FirstName LastName, or even FirstName MiddleInitial LastName, code can easily be written to handle the parsing. But it's usually not that simple when it comes to names!

It's usually things like

FirstName LastName

FirstName MiddleInitial LastName

FirstName LastName Qualifier (Sr, Jr, III, etc)

Mr/Mrs FirstName LastName

Mr/Mrs FirstName MiddleInitial LastName

FirstName MiddleInitial LastName Title (M.D. Esq. CEO, etc)

and so forth, including the two part LastNames, such as van Allen and that guy that Bush has been chasing for so long! And so, in the end, you usually end up having to visually inspecting all records and making adjustments accordingly.

If the majority of names are FirstName LastName, or FirstName MiddleInitial LastName, using code to start the parsing process and then inspecting the data and making corrections may be worth the trouble, especially if you're talking about a lot of records. It all depends.

BTW, the other similar PIA we see involves parsing addresses! Years ago I moonlighted, doing data entry for one of the largest banks in the world. They'd bought out another regional bank and were trying to convert/format the customer addresses to fall in line with their own system's formatting. After a team of 6 programmers spent 4 months trying to figure out how to do this "automatically" they finally bit the bullet and hired data input personnel to scan the data and make the corrections.

The bottom line is to remember the Cardinal Rule of Relational Databases: One Piece of Data/One Field!

Good Luck and Welcome to Bytes!

Linq ;0)>
Jan 6 '09 #4
Hahahahahahhaha!
Thanks guys for the replies.................
I love that Cardinal Rule, not so much a fan of cleaning up other people's crap!!!
Thanks again!!!
Jan 6 '09 #5
ADezii
8,834 Expert 8TB
@artemetis
I responded to a similar Thread not that long ago involving names which may/may not have Prefixes, Suffixes, First, Last, Titles, etc. As soon as I can retrieve it, I'll post the Link to it. It will definately point you in the right direction, but as Linq stated, there is no foolproof Method to accomplish this.
Got it!
http://bytes.com/topic/access/answer...unction-script
Jan 6 '09 #6
NeoPa
32,556 Expert Mod 16PB
@artemetis
ADezii's link will probably get you off to a good start.

As for handling 'other people's crap', we always hope they can pass us something clean and tidy, but don't rely too heavily on that. In the real world you're lucky if you get too much passed on that doesn't need a fair amount of 'cleaning out' ;D.
Jan 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Peter A. Schott | last post by:
I've got a file that seems to come across more like a dictionary from what I can tell. Something like the following format: ###,1,val_1,2,val_2,3,val_3,5,val_5,10,val_10...
5
by: BStorm | last post by:
I have a transaction log file where the DataSet table's Description column is actually delimited into "subcolumns" based upon the transaction id. I would like to parse these into separate fields...
24
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and...
5
by: Theresa Hancock via AccessMonster.com | last post by:
I have an Excel table I need to import into Access. The name is entered into one field "Name". I'd like to have two fields in Access, FirstName and LastName. How do I do this. -- Message posted...
11
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a...
5
by: Takeadoe | last post by:
I've got a favor to ask - Consider the following numeric field: 511 6805 3205 403 I need to make 2 new numeric fields from this variable, call it CS
9
by: RMC | last post by:
Hello, I'm looking for a way to parse/format a memo field within a report. The Access 2000 database (application) has an equipment table that holds a memo field. Within the report, the memo...
5
by: portCo | last post by:
Hi there, I am re-organizing the database. We used to have field 'names' in our table for our first name and last name. However, I want to have those names in different field. FYI, I have two...
14
by: jmDesktop | last post by:
I have a food menu. Each area, like beverages, grill, etc. have items under them, Coke, Tea, Coffee would be under beverages for example. I want to add a new drink to beverages. In my database...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.