Solved

Data seperation in a field

Posted on 2010-09-17
6
304 Views
Last Modified: 2012-05-10
I have a table with data
in a field that I need
seperated into other fields.
The field with the data is called
FLOC_LABEL.
The data is seperated by a ".",
like ED.RAM.WARN.L131.P161.
The first segment Needs to go
into a field called "Distribution".
The second segment needs to go
into a field called "District".
The third segment needs to go into
a field called Sub_Area.
The fourth segment needs to go
into a field called LineNo.
The fifth segment needs to go
into a field called "Line_Seg".
There are other fields in this
table, so basically I would be
adding the five new fields.
Any help is greatly appreciated.
Thanks


0
Comment
Question by:donnie91910
6 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 250 total points
ID: 33703427
create this in modules

Function splitNGet(s As String, n As Integer, seperator As String)
  Arr = Split(s, seperator)
  splitNGet = (Arr(n - 1))
End Function

use

select
splitnget("ED.RAM.WARN.L131.P161.",1,".") as Distribution,
splitnget("ED.RAM.WARN.L131.P161.",2,".") as District,
...
from MyTable
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 33703438
you will need a UDF function to do that

place this codes in a regular Module (not the Form module)

Function SplitField(ByVal idx As Integer, ByVal sValue As String) As String

    Dim infArr() As String
   
    SplitField = ""
    If sValue <> "" Then
        infArr = Split(sValue, ".")
        Select Case idx
            Case 1
                SplitField = infArr(0)
            Case 2
                If UBound(infArr) > 0 Then SplitField = infArr(1)
            Case 3
                If UBound(infArr) > 1 Then SplitField = infArr(2)
            Case 4
                If UBound(infArr) > 2 Then SplitField = infArr(3)
            Case 5
                If UBound(infArr) > 2 Then SplitField = infArr(4)

        End Select
    End If
End Function



to use in a query

select [FLOC_LABEL]
,SplitField(1,[FLOC_LABEL]) as Distribution
,SplitField(2,[FLOC_LABEL]) as District
,SplitField(3,[FLOC_LABEL]) as Sub_Area
,SplitField(4,[FLOC_LABEL]) as LineNo
,SplitField(5,[FLOC_LABEL]) as LineSeq
From NameOftable


you can also use the a query to update the fields in your table
by converting the Select query into an Update query




0
 

Author Closing Comment

by:donnie91910
ID: 33704210
worked great.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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, when working with VBA, learn some techniques for writing readable and easily maintained code.

832 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