Solved

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

Posted on 2010-08-13
10
493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

730 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