Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / March 2006

Tip: Looking for answers? Try searching our database.

Parse one field into multiple columns

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mattc66 - 24 Mar 2006 08:45 GMT
Hi All,

Need some help. I have read the Mid, Left and Right options. But I have some
data that may very.

The Data will come as follows (1 FLD):
CC,4.5x5x7,C2
CC,4x5x7,C2
PB,5.5x5.5x8,C2

I need to split up the data above into 5 columns.
FLD1    FLD2    FLD3    FLD4    FLD5
CC    4.5    5    7    C2
CC    4    5    7    C2
PB    5.5    5.5    8    C2

Please help.
Duane Hookom - 24 Mar 2006 13:24 GMT
Your data looks very consistent. If it is always separated like ,xx, then
you can use this function:
Public Function ParseData(pstrText As String, _
       pintColumn As Integer) As String
   'pstrText is the value in
   'pintColumn is the column (1-5)
   'parse values like
   'CC,4.5x5x7,C2
   'CC,4x5x7,C2
   'PB,5.5x5.5x8,C2
   'to
   ' 1   2     3   4    5
   '== ===   ===   =   ==
   'CC 4.5   5     7   C2
   'CC 4     5     7   C2
   'PB 5.5   5.5   8   C2
   Dim arCSV
   Dim arX
   'create 3 comma separated values
   arCSV = Split(pstrText, ",")
   'split the "x" separated values
   arX = Split(arCSV(1), "x")
   Select Case pintColumn
       Case 1
           ParseData = arCSV(0)
       Case 2
           ParseData = arX(0)
       Case 3
           ParseData = arX(1)
       Case 4
           ParseData = arX(2)
       Case 5
           ParseData = arCSV(2)
   End Select
End Function

Signature

Duane Hookom
MS Access MVP
--

> Hi All,
>
[quoted text clipped - 14 lines]
>
> Please help.
mattc66 - 24 Mar 2006 17:31 GMT
That looks good - Call me new, but how do I execute. Do I place this in a
query?

>Your data looks very consistent. If it is always separated like ,xx, then
>you can use this function:
[quoted text clipped - 37 lines]
>>
>> Please help.
mattc66 - 24 Mar 2006 17:43 GMT
I want to be clear, I need to place each seperated value into its own field.
table
fld1 = cc,4.5x5x7,c2 (run the function, and it placed the data into the
proper flds).
fld2 = cc
fld3 = 4.5
fld4 = 5
fld5 = 7
fld6 = c2

Its hard at times to describe without pictures.

Thanks for all your help.

>Your data looks very consistent. If it is always separated like ,xx, then
>you can use this function:
[quoted text clipped - 37 lines]
>>
>> Please help.
Duane Hookom - 24 Mar 2006 18:04 GMT
You open a new blank Module and paste the function into the module. Save the
module as "modCalcs".
You can then use the function  ParseData() almost anywhere you would use any
other function. For instance you can create a column in a query like:
  Fld2: ParseData([fld1], 1)
or
  Fld6: ParseData([fld1], 5)

Signature

Duane Hookom
MS Access MVP
--

>I want to be clear, I need to place each seperated value into its own
>field.
[quoted text clipped - 52 lines]
>>>
>>> Please help.
mattc66 - 24 Mar 2006 20:35 GMT
That worked great..

I have another task that is similure. I will create a new thread.

>You open a new blank Module and paste the function into the module. Save the
>module as "modCalcs".
[quoted text clipped - 9 lines]
>>>>
>>>> Please help.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.