Solved

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

Posted on 2010-08-13
10
489 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

747 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

13 Experts available now in Live!

Get 1:1 Help Now