parse out a text field

L

LGarcia

Hi all,
I was given a table with a field that contains comma delimited data. The
data in the field looks like this:
100,08/04/2004,3,1,0,,.
I'm using this to parse out the first set of text up to the first comma:
Trim(Left([AuditAfter],InStr([AuditAfter],",")-1))
I'm then using Trim(Mid([AuditAfter],InStr([AuditAfter],",")+1)) to return
the next set of text but it returns everything to the right of the first
comma . Can someone show me how to parse out only the text between the next
set of commas, and then the next...
Thanks!!
LGarcia
 
M

Mike Painter

LGarcia said:
Hi all,
I was given a table with a field that contains comma delimited data.
The data in the field looks like this:
100,08/04/2004,3,1,0,,.
I'm using this to parse out the first set of text up to the first
comma: Trim(Left([AuditAfter],InStr([AuditAfter],",")-1))
I'm then using Trim(Mid([AuditAfter],InStr([AuditAfter],",")+1)) to
return the next set of text but it returns everything to the right of
the first comma . Can someone show me how to parse out only the text
between the next set of commas, and then the next...
Thanks!!
LGarcia

DIM SomeArray(100)
DIM SecondValue
SomeArray = Split(YourField, ",")
SecondValue - SomeArray(2)

or
DIM SomeArray(2)
DIM SecondValue
SomeArray = Split(YourField, ",",2)
SecondValue - SomeArray(2)
 
F

fredg

Hi all,
I was given a table with a field that contains comma delimited data. The
data in the field looks like this:
100,08/04/2004,3,1,0,,.
I'm using this to parse out the first set of text up to the first comma:
Trim(Left([AuditAfter],InStr([AuditAfter],",")-1))
I'm then using Trim(Mid([AuditAfter],InStr([AuditAfter],",")+1)) to return
the next set of text but it returns everything to the right of the first
comma . Can someone show me how to parse out only the text between the next
set of commas, and then the next...
Thanks!!
LGarcia

In a query?

If you have Access 2000 or newer, copy and paste the following code
into a new Module.

Public Function ParseText(TextIn As String, X) As Variant

On Error Resume Next
Dim var As Variant
var = Split(TextIn, ",", -1)
ParseText = var(X)

End Function

=======

Call it from a query:
FirstGroup:parseText([FieldName],0)

SecondGroup:parseText([FieldName],1)

ThirdGroup:parseText([FieldName],2)

etc.
Notice the groups start a Zero.

You'll want to limit records to only those with data in that field.
 
L

LGarcia

Wow! I wasn't aware that you could call a function from a query. It works
beautifully! Thanks!!!


fredg said:
Hi all,
I was given a table with a field that contains comma delimited data. The
data in the field looks like this:
100,08/04/2004,3,1,0,,.
I'm using this to parse out the first set of text up to the first comma:
Trim(Left([AuditAfter],InStr([AuditAfter],",")-1))
I'm then using Trim(Mid([AuditAfter],InStr([AuditAfter],",")+1)) to return
the next set of text but it returns everything to the right of the first
comma . Can someone show me how to parse out only the text between the next
set of commas, and then the next...
Thanks!!
LGarcia

In a query?

If you have Access 2000 or newer, copy and paste the following code
into a new Module.

Public Function ParseText(TextIn As String, X) As Variant

On Error Resume Next
Dim var As Variant
var = Split(TextIn, ",", -1)
ParseText = var(X)

End Function

=======

Call it from a query:
FirstGroup:parseText([FieldName],0)

SecondGroup:parseText([FieldName],1)

ThirdGroup:parseText([FieldName],2)

etc.
Notice the groups start a Zero.

You'll want to limit records to only those with data in that field.
 
G

Guest

duhhhhhhhhhhhh.............................
Serious brain cramp moment.
After I little thought, found this solution both simple and elegant.
Solves all my paring problems.
Thank you.

Andre726 said:
This looks like the answer to my problem as well - but a few more details
would help. My table name is Orders. The field I want to parse is called
"description" and the fields I want to fill From description are called
"size", "material" and "grade" respectively.
Question(s):
Is the Function "ParseText" input as given..given the above?
In the query, do I replace firstgroup:...secondgroup:...and thirdgroup:...
with size, material and grade? Use [description] as my Fieldname?
If I get this to work, it solves all my text parsing problems in one fell
swoop.
Thanks.

LGarcia said:
Wow! I wasn't aware that you could call a function from a query. It works
beautifully! Thanks!!!


fredg said:
On Wed, 4 Aug 2004 11:06:03 -0500, LGarcia wrote:

Hi all,
I was given a table with a field that contains comma delimited data. The
data in the field looks like this:
100,08/04/2004,3,1,0,,.
I'm using this to parse out the first set of text up to the first comma:
Trim(Left([AuditAfter],InStr([AuditAfter],",")-1))
I'm then using Trim(Mid([AuditAfter],InStr([AuditAfter],",")+1)) to return
the next set of text but it returns everything to the right of the first
comma . Can someone show me how to parse out only the text between the next
set of commas, and then the next...
Thanks!!
LGarcia

In a query?

If you have Access 2000 or newer, copy and paste the following code
into a new Module.

Public Function ParseText(TextIn As String, X) As Variant

On Error Resume Next
Dim var As Variant
var = Split(TextIn, ",", -1)
ParseText = var(X)

End Function

=======

Call it from a query:
FirstGroup:parseText([FieldName],0)

SecondGroup:parseText([FieldName],1)

ThirdGroup:parseText([FieldName],2)

etc.
Notice the groups start a Zero.

You'll want to limit records to only those with data in that field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

parse string to multi records 2
Parse a field into 2 fields 4
Instr parsing with a comma delimited string 3
trim a field 2
Parsing Question 4
Parse string 3
Line Input 4
Remove a comma 1

Top