Solved

How do I batch cut and paste across columns in Access 2007

Posted on 2010-08-13
10
490 Views
Last Modified: 2013-11-27
I have a Access Database that has a name field with both last, first and middle names (ex: Smith, John H.) in the same field. I want to separate them into individual columns and fields. There are 12,000 names.
How can I do this?
0
Comment
Question by:mitzilla
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 33430534
place this function in a regular module

then write a query like this

select [name], splitname(1,[name]) as firstName,splitname(2,[name]) as LastName,splitname(1,[name]) as MI
from tableX


Function SplitName(ByVal idx As Integer, ByVal sName As String) As String



    Dim infArr() As String

   

    SplitName = ""

    If sName <> "" Then

        infArr = Split(sName, " ")

        Select Case idx

            Case 1

                SplitName = infArr(0)

            Case 2

                If UBound(infArr) > 0 Then SplitName = infArr(1)

            Case 3

                If UBound(infArr) > 1 Then SplitName = infArr(2)

            Case 4

                If UBound(infArr) > 2 Then SplitName = infArr(3)

            Case 5

                If UBound(infArr) > 2 Then SplitName = infArr(4)



        End Select

    End If

End Function

Open in new window

0
 
LVL 6

Expert Comment

by:Dangle79
ID: 33430734
I don't know that there's an easy way just within Access to do it, but it could be done with a vb-script. if you've already got a connection to the database w/ your ASP page and the added columns exist...

pull recordset
  FOR each record
    set recordID  < key variable from record
    set namevariable  < from original field
    separateName = split(namevariable, " ")
    sql update recordID  lastname = separateName(0) firstname = separateName(1) initial = separateName(2)

could do some additional fiddling with the text to peel off the commas and periods as well. save that asp page (i'm assuming from the zones listed you're working within a web application) and run it once to see what you get. obviously run against a backup copy of your database first.
0
 
LVL 6

Expert Comment

by:c661jmb
ID: 33430836
You could export the table into excel and then open the excel file, then in three columns create formulas.

I have attached a sample spreadsheet with the formulas.

This will work so long as the full name column has the data in the format:

Surname, Forname Initial


sample.xls
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33431168
mitzilla,If the data are all formatted correctly, then this can usually be handled with formulas.  That said, deviations in formatting can really, really trip you up: some records may have titles and/or suffixes and some not, for example.I go over a number of the challenges, and offer some very robust VBA code, in dealing with this in my article here:http://www.experts-exchange.com/Programming/Languages/Visual_Basic/A_1819-Parsing-Names-in-MS-Office-Visual-Basic-6-and-Visual-Basic-for-Applications.htmlPatrick
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33431179
That article includes a sample MDB file.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33431189
Also keep in mind that multi-word name parts are always, always going to give you fits :)
0
 
LVL 3

Author Comment

by:mitzilla
ID: 33434289
Thanks everyone!
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 33434331
mitzilla,

you did not even try the first post ???
0
 
LVL 3

Author Comment

by:mitzilla
ID: 33447330
Capricorn1,
Actually I  tried all of the posts. But my understanding of access is still really really at a beginner status.
I couldn't get the module to be seen by the query.  I had to poke around for like fifteen minutes before I even found that feature. Apologies, I'm sure yours would of worked perfectly and I did give it a shot. I just couldn't get my head around it.
Thanks
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 33447503
<I couldn't get the module to be seen by the query.  >

you could have posted a question, so the other will know if you are having difficulty with the posted suggestion and can post information to help you with the problem.

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now