Extracting data from strings

G

Guest

I have some text strings that I need to extract specific data from.

SAMPLES:
Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

Rewarehouse Pick: 4610060729 QTY: 44 LOC: A 101-111-T SERIAL:

Rewarehouse Stored: 4610060729 QTY: 44 LOC: A 101-111-A SERIAL:

I need to extract the task: Stored Item; Rewarehouse pick; Rewarehouse
Stored.
The task always ends at the ":".
I need to extract the item number. It is usually 10 characters but some are
14 characters, The item number is always followed by QTY.
I need to extract the QTY. It is usually a number from 0 to 10,000. It
always follows the Qty's ":" and ends 1 space before the LOC.
Finally, I need to extract the LOC. It is always 11 characters.
In the past I have used Excel and used the MID, SEARCH, and other functions
to extract from the strings but I would like to import the CSV file directly
into Access and do it all from there.
Thanking everyone in advance.
Sgurdon
 
G

Guest

If you were successful in Excel, then this will be a snap for you in Access.

Instead of the SEARCH function use the InStr function along with Left, Mid
and Right and you'll be done in no time.

You would do this in a query, not a table.

Seth Schwarm
 
G

Guest

Not snapping in Access; maybe i'm missing something.
This the formula I used in Excel to extract the first variable, how does it
translate to Access?

Cell A2=date
Cell B2=Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

This is the function I use: "=MID(B2,1,SEARCH(":",B2)-1)" it brings back
Stored ITEM

If I can get that translated to use the InStr function I should be able to
figure how to use it to pull all of the tasks.

Expr1: Mid([action],1,InStr(":",[action])-1)

I tried replacing "Search" with "InStr" and "B2" with "[action]", the name
of the field containing the string, but it returns an error message.
 
T

Tom Lake

Sgurdon said:
Not snapping in Access; maybe i'm missing something.
This the formula I used in Excel to extract the first variable, how does
it
translate to Access?

Cell A2=date
Cell B2=Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

This is the function I use: "=MID(B2,1,SEARCH(":",B2)-1)" it brings back
Stored ITEM

If Stored ITEM is all numeric, here's one way:
=Trim(Str(Val(Mid(a$, 14))))

The 14 gets you past the "Stored ITEM:" , Val takes the value of stored item
Str converts it to a string and Trim trims off the sign space.

Make sure the field name in the record is B2 and that the control on your
form or report is NOT called B2.

Tom Lake
 
T

Tom Lake

If Stored ITEM is all numeric, here's one way:
=Trim(Str(Val(Mid(a$, 14))))

Make sure the field name in the record is B2 and that the control on your
form or report is NOT called B2.

Oops! I changed B2 to a$ in testing and didn't change it back, The
above should be:

=Trim(Str(Val(Mid(B2, 14))))

Tom Lake
 
G

Guest

Sgurdon:

Ok, well sorry - I assumed you knew more about Access. Let's back up and
discuss a couple things.

You will import your data into a table. A table stores data and not
formulas. The only similarity between Access' table and Excel is the fact
they look similar and each box is called a cell. The similarities absolutely
end there. Now you are in Access world - things are different and you
accomplish tasks using different objects versus cell or sheet manipulation.

I am not going to explain the details of a table and its design view versus
data view, but you need to conceptualize each row is a record and each column
is a field in that record and you don't/can't store formulas/calculated
values in a table. Instead we use queries.

In your case you need to create a new query in design view, then add the
table which contains your imported data onto the Layout Area (top part of
query design screen). The grided area is called the Design Grid. You drag
fields from tables in the Layout Area down to a column in the Design Grid.
You also create formulas (referred to as calculated fields in Access) in the
Design Grid.

In your case you do not need to drag any fields down to the design to build
a calculated field. Your formulas will be built along the same logic used in
Excel, using many of the same function names you used in Excel (except SEARCH
is now what we call InStr). In Access we don't use the equals sign (=) in
formulas in queries; it is improper syntax. Just begin typing your formula
in the row labeled Field.

In Access we don't refer to data by using cell intersection names such as
A2, G74; we use field names. When you write a formula it is assumed/implied
you are working with a record in a table. You don't reference fields/values
in other records, the context is the one record in the table you are working
with. Most folks really struggle with this coming from Excel, but it just is.

So anytime you are thinking of referring to cell A1 you would instead type
the field name from the table you are working with in the Layout Area.
Remember, cell references are a thing of Excel, not Access. Now you are
working with fields (columns) and records (rows). Once you enter a formula
in a query it will calculate a value for each record in the table. There is
no AutoFilling or copying and pasting of formulas. What you do for one
record is done for all records in a query.

A note about calculated fields: after you enter your formula, then tab out
of the field or click elsewhere you will notice a name is given to your to
your formula - Expr1:. This is because in a sense you have created a new
'field' and every field must have a name. You will notice this name as the
column header where you are used to seeing A, B, C, D, E, F. You can rename
the field to something meaningful by selecting Expr and overwriting it. You
will learn in time to do this when entering your formula similar to - Item:
Mid( . . .

See how this helps you, and then come back with additional questions.

Seth Schwarm


Sgurdon said:
Not snapping in Access; maybe i'm missing something.
This the formula I used in Excel to extract the first variable, how does it
translate to Access?

Cell A2=date
Cell B2=Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

This is the function I use: "=MID(B2,1,SEARCH(":",B2)-1)" it brings back
Stored ITEM

If I can get that translated to use the InStr function I should be able to
figure how to use it to pull all of the tasks.

Expr1: Mid([action],1,InStr(":",[action])-1)

I tried replacing "Search" with "InStr" and "B2" with "[action]", the name
of the field containing the string, but it returns an error message.
--
Always in search of knowledge


Seth Schwarm said:
If you were successful in Excel, then this will be a snap for you in Access.

Instead of the SEARCH function use the InStr function along with Left, Mid
and Right and you'll be done in no time.

You would do this in a query, not a table.

Seth Schwarm
 
G

Guest

Thank you Seth,
I haven't gotten the results I need yet but you have put me on the right
track. I will have what I need shortly with a little experimentation and
practice.
--
Always in search of knowledge


Seth Schwarm said:
Sgurdon:

Ok, well sorry - I assumed you knew more about Access. Let's back up and
discuss a couple things.

You will import your data into a table. A table stores data and not
formulas. The only similarity between Access' table and Excel is the fact
they look similar and each box is called a cell. The similarities absolutely
end there. Now you are in Access world - things are different and you
accomplish tasks using different objects versus cell or sheet manipulation.

I am not going to explain the details of a table and its design view versus
data view, but you need to conceptualize each row is a record and each column
is a field in that record and you don't/can't store formulas/calculated
values in a table. Instead we use queries.

In your case you need to create a new query in design view, then add the
table which contains your imported data onto the Layout Area (top part of
query design screen). The grided area is called the Design Grid. You drag
fields from tables in the Layout Area down to a column in the Design Grid.
You also create formulas (referred to as calculated fields in Access) in the
Design Grid.

In your case you do not need to drag any fields down to the design to build
a calculated field. Your formulas will be built along the same logic used in
Excel, using many of the same function names you used in Excel (except SEARCH
is now what we call InStr). In Access we don't use the equals sign (=) in
formulas in queries; it is improper syntax. Just begin typing your formula
in the row labeled Field.

In Access we don't refer to data by using cell intersection names such as
A2, G74; we use field names. When you write a formula it is assumed/implied
you are working with a record in a table. You don't reference fields/values
in other records, the context is the one record in the table you are working
with. Most folks really struggle with this coming from Excel, but it just is.

So anytime you are thinking of referring to cell A1 you would instead type
the field name from the table you are working with in the Layout Area.
Remember, cell references are a thing of Excel, not Access. Now you are
working with fields (columns) and records (rows). Once you enter a formula
in a query it will calculate a value for each record in the table. There is
no AutoFilling or copying and pasting of formulas. What you do for one
record is done for all records in a query.

A note about calculated fields: after you enter your formula, then tab out
of the field or click elsewhere you will notice a name is given to your to
your formula - Expr1:. This is because in a sense you have created a new
'field' and every field must have a name. You will notice this name as the
column header where you are used to seeing A, B, C, D, E, F. You can rename
the field to something meaningful by selecting Expr and overwriting it. You
will learn in time to do this when entering your formula similar to - Item:
Mid( . . .

See how this helps you, and then come back with additional questions.

Seth Schwarm


Sgurdon said:
Not snapping in Access; maybe i'm missing something.
This the formula I used in Excel to extract the first variable, how does it
translate to Access?

Cell A2=date
Cell B2=Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

This is the function I use: "=MID(B2,1,SEARCH(":",B2)-1)" it brings back
Stored ITEM

If I can get that translated to use the InStr function I should be able to
figure how to use it to pull all of the tasks.

Expr1: Mid([action],1,InStr(":",[action])-1)

I tried replacing "Search" with "InStr" and "B2" with "[action]", the name
of the field containing the string, but it returns an error message.
--
Always in search of knowledge


Seth Schwarm said:
If you were successful in Excel, then this will be a snap for you in Access.

Instead of the SEARCH function use the InStr function along with Left, Mid
and Right and you'll be done in no time.

You would do this in a query, not a table.

Seth Schwarm

:

I have some text strings that I need to extract specific data from.

SAMPLES:
Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

Rewarehouse Pick: 4610060729 QTY: 44 LOC: A 101-111-T SERIAL:

Rewarehouse Stored: 4610060729 QTY: 44 LOC: A 101-111-A SERIAL:

I need to extract the task: Stored Item; Rewarehouse pick; Rewarehouse
Stored.
The task always ends at the ":".
I need to extract the item number. It is usually 10 characters but some are
14 characters, The item number is always followed by QTY.
I need to extract the QTY. It is usually a number from 0 to 10,000. It
always follows the Qty's ":" and ends 1 space before the LOC.
Finally, I need to extract the LOC. It is always 11 characters.
In the past I have used Excel and used the MID, SEARCH, and other functions
to extract from the strings but I would like to import the CSV file directly
into Access and do it all from there.
Thanking everyone in advance.
Sgurdon
 
G

Guest

Thanks Tom,
I will try this once I achieve the results I need using the InStr function.
I don't want to get thrown off of my current track, but I can see that this
formula will come in handy.
 
G

Guest

Seth, I have a similar request. I need to extract the decimal and digits
past the second "*" in the example below. I entered this funtion: Expr1:
InStr("*.",[Rate]), but just got ones and zeros, so don't really know how it
works. [Rate] is my field name.

0*999999999999*.008

Problem is that sometimes there are multiple digits to the right of the
decimal. This is data stored as text. I don't have access to the original
data, so I can't change the report, I can only attempt to extract the data I
need. I will receive these reports weekly.

Thank you for your help!

Seth Schwarm said:
Sgurdon:

Ok, well sorry - I assumed you knew more about Access. Let's back up and
discuss a couple things.

You will import your data into a table. A table stores data and not
formulas. The only similarity between Access' table and Excel is the fact
they look similar and each box is called a cell. The similarities absolutely
end there. Now you are in Access world - things are different and you
accomplish tasks using different objects versus cell or sheet manipulation.

I am not going to explain the details of a table and its design view versus
data view, but you need to conceptualize each row is a record and each column
is a field in that record and you don't/can't store formulas/calculated
values in a table. Instead we use queries.

In your case you need to create a new query in design view, then add the
table which contains your imported data onto the Layout Area (top part of
query design screen). The grided area is called the Design Grid. You drag
fields from tables in the Layout Area down to a column in the Design Grid.
You also create formulas (referred to as calculated fields in Access) in the
Design Grid.

In your case you do not need to drag any fields down to the design to build
a calculated field. Your formulas will be built along the same logic used in
Excel, using many of the same function names you used in Excel (except SEARCH
is now what we call InStr). In Access we don't use the equals sign (=) in
formulas in queries; it is improper syntax. Just begin typing your formula
in the row labeled Field.

In Access we don't refer to data by using cell intersection names such as
A2, G74; we use field names. When you write a formula it is assumed/implied
you are working with a record in a table. You don't reference fields/values
in other records, the context is the one record in the table you are working
with. Most folks really struggle with this coming from Excel, but it just is.

So anytime you are thinking of referring to cell A1 you would instead type
the field name from the table you are working with in the Layout Area.
Remember, cell references are a thing of Excel, not Access. Now you are
working with fields (columns) and records (rows). Once you enter a formula
in a query it will calculate a value for each record in the table. There is
no AutoFilling or copying and pasting of formulas. What you do for one
record is done for all records in a query.

A note about calculated fields: after you enter your formula, then tab out
of the field or click elsewhere you will notice a name is given to your to
your formula - Expr1:. This is because in a sense you have created a new
'field' and every field must have a name. You will notice this name as the
column header where you are used to seeing A, B, C, D, E, F. You can rename
the field to something meaningful by selecting Expr and overwriting it. You
will learn in time to do this when entering your formula similar to - Item:
Mid( . . .

See how this helps you, and then come back with additional questions.

Seth Schwarm


Sgurdon said:
Not snapping in Access; maybe i'm missing something.
This the formula I used in Excel to extract the first variable, how does it
translate to Access?

Cell A2=date
Cell B2=Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

This is the function I use: "=MID(B2,1,SEARCH(":",B2)-1)" it brings back
Stored ITEM

If I can get that translated to use the InStr function I should be able to
figure how to use it to pull all of the tasks.

Expr1: Mid([action],1,InStr(":",[action])-1)

I tried replacing "Search" with "InStr" and "B2" with "[action]", the name
of the field containing the string, but it returns an error message.
--
Always in search of knowledge


Seth Schwarm said:
If you were successful in Excel, then this will be a snap for you in Access.

Instead of the SEARCH function use the InStr function along with Left, Mid
and Right and you'll be done in no time.

You would do this in a query, not a table.

Seth Schwarm

:

I have some text strings that I need to extract specific data from.

SAMPLES:
Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

Rewarehouse Pick: 4610060729 QTY: 44 LOC: A 101-111-T SERIAL:

Rewarehouse Stored: 4610060729 QTY: 44 LOC: A 101-111-A SERIAL:

I need to extract the task: Stored Item; Rewarehouse pick; Rewarehouse
Stored.
The task always ends at the ":".
I need to extract the item number. It is usually 10 characters but some are
14 characters, The item number is always followed by QTY.
I need to extract the QTY. It is usually a number from 0 to 10,000. It
always follows the Qty's ":" and ends 1 space before the LOC.
Finally, I need to extract the LOC. It is always 11 characters.
In the past I have used Excel and used the MID, SEARCH, and other functions
to extract from the strings but I would like to import the CSV file directly
into Access and do it all from there.
Thanking everyone in advance.
Sgurdon
 
J

John Spencer

What are the rules for deciding?
Are there always two asterisks (*)?
Do you always have an asterisk followed by a period as the breakpoint?

Is the first asterisk always in the 2nd position?

If the first asterisk always occurs in the first2 characters, then this
expression should work

Mid([TheField],Instr(3,[TheField],"*")+1)

If the first asterisk appears somewhere in the string then you need a
slightly more complex expression

Mid([TheField],Instr(Instr(1,[TheField],"*")+1 ,[TheField],"*")+1)

I suggest you look up the Mid and Instr functions in the VBA help for an
understanding of what they do.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

Carmen said:
Seth, I have a similar request. I need to extract the decimal and digits
past the second "*" in the example below. I entered this funtion: Expr1:
InStr("*.",[Rate]), but just got ones and zeros, so don't really know how
it
works. [Rate] is my field name.

0*999999999999*.008

Problem is that sometimes there are multiple digits to the right of the
decimal. This is data stored as text. I don't have access to the
original
data, so I can't change the report, I can only attempt to extract the data
I
need. I will receive these reports weekly.

Thank you for your help!

Seth Schwarm said:
Sgurdon:

Ok, well sorry - I assumed you knew more about Access. Let's back up and
discuss a couple things.

You will import your data into a table. A table stores data and not
formulas. The only similarity between Access' table and Excel is the
fact
they look similar and each box is called a cell. The similarities
absolutely
end there. Now you are in Access world - things are different and you
accomplish tasks using different objects versus cell or sheet
manipulation.

I am not going to explain the details of a table and its design view
versus
data view, but you need to conceptualize each row is a record and each
column
is a field in that record and you don't/can't store formulas/calculated
values in a table. Instead we use queries.

In your case you need to create a new query in design view, then add the
table which contains your imported data onto the Layout Area (top part of
query design screen). The grided area is called the Design Grid. You
drag
fields from tables in the Layout Area down to a column in the Design
Grid.
You also create formulas (referred to as calculated fields in Access) in
the
Design Grid.

In your case you do not need to drag any fields down to the design to
build
a calculated field. Your formulas will be built along the same logic
used in
Excel, using many of the same function names you used in Excel (except
SEARCH
is now what we call InStr). In Access we don't use the equals sign (=)
in
formulas in queries; it is improper syntax. Just begin typing your
formula
in the row labeled Field.

In Access we don't refer to data by using cell intersection names such as
A2, G74; we use field names. When you write a formula it is
assumed/implied
you are working with a record in a table. You don't reference
fields/values
in other records, the context is the one record in the table you are
working
with. Most folks really struggle with this coming from Excel, but it
just is.

So anytime you are thinking of referring to cell A1 you would instead
type
the field name from the table you are working with in the Layout Area.
Remember, cell references are a thing of Excel, not Access. Now you are
working with fields (columns) and records (rows). Once you enter a
formula
in a query it will calculate a value for each record in the table. There
is
no AutoFilling or copying and pasting of formulas. What you do for one
record is done for all records in a query.

A note about calculated fields: after you enter your formula, then tab
out
of the field or click elsewhere you will notice a name is given to your
to
your formula - Expr1:. This is because in a sense you have created a new
'field' and every field must have a name. You will notice this name as
the
column header where you are used to seeing A, B, C, D, E, F. You can
rename
the field to something meaningful by selecting Expr and overwriting it.
You
will learn in time to do this when entering your formula similar to -
Item:
Mid( . . .

See how this helps you, and then come back with additional questions.

Seth Schwarm


Sgurdon said:
Not snapping in Access; maybe i'm missing something.
This the formula I used in Excel to extract the first variable, how
does it
translate to Access?

Cell A2=date
Cell B2=Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

This is the function I use: "=MID(B2,1,SEARCH(":",B2)-1)" it brings
back
Stored ITEM

If I can get that translated to use the InStr function I should be
able to
figure how to use it to pull all of the tasks.

Expr1: Mid([action],1,InStr(":",[action])-1)

I tried replacing "Search" with "InStr" and "B2" with "[action]", the
name
of the field containing the string, but it returns an error message.
--
Always in search of knowledge


:

If you were successful in Excel, then this will be a snap for you in
Access.

Instead of the SEARCH function use the InStr function along with
Left, Mid
and Right and you'll be done in no time.

You would do this in a query, not a table.

Seth Schwarm

:

I have some text strings that I need to extract specific data from.

SAMPLES:
Stored ITEM: 4610201465 QTY: 5 LOC: A 105-130-C

Rewarehouse Pick: 4610060729 QTY: 44 LOC: A 101-111-T SERIAL:

Rewarehouse Stored: 4610060729 QTY: 44 LOC: A 101-111-A SERIAL:

I need to extract the task: Stored Item; Rewarehouse pick;
Rewarehouse
Stored.
The task always ends at the ":".
I need to extract the item number. It is usually 10 characters but
some are
14 characters, The item number is always followed by QTY.
I need to extract the QTY. It is usually a number from 0 to
10,000. It
always follows the Qty's ":" and ends 1 space before the LOC.
Finally, I need to extract the LOC. It is always 11 characters.
In the past I have used Excel and used the MID, SEARCH, and other
functions
to extract from the strings but I would like to import the CSV file
directly
into Access and do it all from there.
Thanking everyone in advance.
Sgurdon
 

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

Top