extract part of a field

  • Thread starter Thread starter Guest
  • Start date Start date
Unless your fields are fixed length, and the "/" is always in the same spot,
you will likely also need the len() and instr() functions. Such as:

Right([YourField],len([YourField])-instr([YourField],"/",1))

HTH, Ted Allen
 
Ted Allen said:
Unless your fields are fixed length, and the "/" is always in the same spot,
you will likely also need the len() and instr() functions. Such as:

Right([YourField],len([YourField])-instr([YourField],"/",1))

You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function. Without
this your expression would error outside of the MS Access UI.

Jamie.

--
 
You're right Jamie, much cleaner solution. I forgot that the mid function
defaults the length to the remainder of the string if ommitted. Also, good
point about the start pos in the Instr() function. I guess I only use it in
Access environment so I hadn't come across that issue.

-Ted Allen

Jamie Collins said:
Ted Allen said:
Unless your fields are fixed length, and the "/" is always in the same spot,
you will likely also need the len() and instr() functions. Such as:

Right([YourField],len([YourField])-instr([YourField],"/",1))

You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function. Without
this your expression would error outside of the MS Access UI.

Jamie.
 
Hello, I used Jamie's solution successfully, however, I'm wondering if
there's a way to extract between to characters. The data I want to extract
will always fall between "-" and ":". Right now I'm picking up everything
after "-".

Thanks,
Mary

Ted Allen said:
You're right Jamie, much cleaner solution. I forgot that the mid function
defaults the length to the remainder of the string if ommitted. Also, good
point about the start pos in the Instr() function. I guess I only use it in
Access environment so I hadn't come across that issue.

-Ted Allen

Jamie Collins said:
Ted Allen said:
Unless your fields are fixed length, and the "/" is always in the same spot,
you will likely also need the len() and instr() functions. Such as:

Right([YourField],len([YourField])-instr([YourField],"/",1))

You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function. Without
this your expression would error outside of the MS Access UI.

Jamie.
 
Something like this, perhaps:

ExtractedString = Mid(Left(OriginalString, InStrRev(OriginalString, ":") -
1), InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>

Mary said:
Hello, I used Jamie's solution successfully, however, I'm wondering if
there's a way to extract between to characters. The data I want to
extract
will always fall between "-" and ":". Right now I'm picking up everything
after "-".

Thanks,
Mary

Ted Allen said:
You're right Jamie, much cleaner solution. I forgot that the mid
function
defaults the length to the remainder of the string if ommitted. Also,
good
point about the start pos in the Instr() function. I guess I only use it
in
Access environment so I hadn't come across that issue.

-Ted Allen

Jamie Collins said:
Unless your fields are fixed length, and the "/" is always in the
same spot,
you will likely also need the len() and instr() functions. Such as:

Right([YourField],len([YourField])-instr([YourField],"/",1))


You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function. Without
this your expression would error outside of the MS Access UI.

Jamie.
 
Ken, I'm getting an "Undefined function, InStrRev" error, this is what I tried:

DESCRIPTION: Mid(Left([DESCR],InStrRev([DESCR],":")-1),InStr([DESCR],"-")+1)

Thanks, Mary

Ken Snell said:
Something like this, perhaps:

ExtractedString = Mid(Left(OriginalString, InStrRev(OriginalString, ":") -
1), InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>

Mary said:
Hello, I used Jamie's solution successfully, however, I'm wondering if
there's a way to extract between to characters. The data I want to
extract
will always fall between "-" and ":". Right now I'm picking up everything
after "-".

Thanks,
Mary

Ted Allen said:
You're right Jamie, much cleaner solution. I forgot that the mid
function
defaults the length to the remainder of the string if ommitted. Also,
good
point about the start pos in the Instr() function. I guess I only use it
in
Access environment so I hadn't come across that issue.

-Ted Allen

:


Unless your fields are fixed length, and the "/" is always in the
same spot,
you will likely also need the len() and instr() functions. Such as:

Right([YourField],len([YourField])-instr([YourField],"/",1))


You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function. Without
this your expression would error outside of the MS Access UI.

Jamie.
 
Which version of ACCESS are you using?

--

Ken Snell
<MS ACCESS MVP>

Mary said:
Ken, I'm getting an "Undefined function, InStrRev" error, this is what I
tried:

DESCRIPTION:
Mid(Left([DESCR],InStrRev([DESCR],":")-1),InStr([DESCR],"-")+1)

Thanks, Mary

Ken Snell said:
Something like this, perhaps:

ExtractedString = Mid(Left(OriginalString, InStrRev(OriginalString,
":") -
1), InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>

Mary said:
Hello, I used Jamie's solution successfully, however, I'm wondering if
there's a way to extract between to characters. The data I want to
extract
will always fall between "-" and ":". Right now I'm picking up
everything
after "-".

Thanks,
Mary

:

You're right Jamie, much cleaner solution. I forgot that the mid
function
defaults the length to the remainder of the string if ommitted. Also,
good
point about the start pos in the Instr() function. I guess I only use
it
in
Access environment so I hadn't come across that issue.

-Ted Allen

:


Unless your fields are fixed length, and the "/" is always in the
same spot,
you will likely also need the len() and instr() functions. Such
as:

Right([YourField],len([YourField])-instr([YourField],"/",1))


You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function.
Without
this your expression would error outside of the MS Access UI.

Jamie.
 
Access 97

Ken Snell said:
Which version of ACCESS are you using?

--

Ken Snell
<MS ACCESS MVP>

Mary said:
Ken, I'm getting an "Undefined function, InStrRev" error, this is what I
tried:

DESCRIPTION:
Mid(Left([DESCR],InStrRev([DESCR],":")-1),InStr([DESCR],"-")+1)

Thanks, Mary

Ken Snell said:
Something like this, perhaps:

ExtractedString = Mid(Left(OriginalString, InStrRev(OriginalString,
":") -
1), InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>

Hello, I used Jamie's solution successfully, however, I'm wondering if
there's a way to extract between to characters. The data I want to
extract
will always fall between "-" and ":". Right now I'm picking up
everything
after "-".

Thanks,
Mary

:

You're right Jamie, much cleaner solution. I forgot that the mid
function
defaults the length to the remainder of the string if ommitted. Also,
good
point about the start pos in the Instr() function. I guess I only use
it
in
Access environment so I hadn't come across that issue.

-Ted Allen

:


Unless your fields are fixed length, and the "/" is always in the
same spot,
you will likely also need the len() and instr() functions. Such
as:

Right([YourField],len([YourField])-instr([YourField],"/",1))


You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function.
Without
this your expression would error outside of the MS Access UI.

Jamie.
 
ahhh......ACCESS 97 doesn't contain that built-in function. So let's change
the expression, assuming that there is only the one : character in the
string:

ExtractedString = Mid(Left(OriginalString, InStr(OriginalString, ":") - 1),
InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>



Mary said:
Access 97

Ken Snell said:
Which version of ACCESS are you using?

--

Ken Snell
<MS ACCESS MVP>

Mary said:
Ken, I'm getting an "Undefined function, InStrRev" error, this is what
I
tried:

DESCRIPTION:
Mid(Left([DESCR],InStrRev([DESCR],":")-1),InStr([DESCR],"-")+1)

Thanks, Mary

:

Something like this, perhaps:

ExtractedString = Mid(Left(OriginalString, InStrRev(OriginalString,
":") -
1), InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>

Hello, I used Jamie's solution successfully, however, I'm wondering
if
there's a way to extract between to characters. The data I want to
extract
will always fall between "-" and ":". Right now I'm picking up
everything
after "-".

Thanks,
Mary

:

You're right Jamie, much cleaner solution. I forgot that the mid
function
defaults the length to the remainder of the string if ommitted.
Also,
good
point about the start pos in the Instr() function. I guess I only
use
it
in
Access environment so I hadn't come across that issue.

-Ted Allen

:


Unless your fields are fixed length, and the "/" is always in
the
same spot,
you will likely also need the len() and instr() functions.
Such
as:

Right([YourField],len([YourField])-instr([YourField],"/",1))


You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function.
Without
this your expression would error outside of the MS Access UI.

Jamie.
 
Perfect! Thanks so much for your help!
Mary

Ken Snell said:
ahhh......ACCESS 97 doesn't contain that built-in function. So let's change
the expression, assuming that there is only the one : character in the
string:

ExtractedString = Mid(Left(OriginalString, InStr(OriginalString, ":") - 1),
InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>



Mary said:
Access 97

Ken Snell said:
Which version of ACCESS are you using?

--

Ken Snell
<MS ACCESS MVP>

Ken, I'm getting an "Undefined function, InStrRev" error, this is what
I
tried:

DESCRIPTION:
Mid(Left([DESCR],InStrRev([DESCR],":")-1),InStr([DESCR],"-")+1)

Thanks, Mary

:

Something like this, perhaps:

ExtractedString = Mid(Left(OriginalString, InStrRev(OriginalString,
":") -
1), InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>

Hello, I used Jamie's solution successfully, however, I'm wondering
if
there's a way to extract between to characters. The data I want to
extract
will always fall between "-" and ":". Right now I'm picking up
everything
after "-".

Thanks,
Mary

:

You're right Jamie, much cleaner solution. I forgot that the mid
function
defaults the length to the remainder of the string if ommitted.
Also,
good
point about the start pos in the Instr() function. I guess I only
use
it
in
Access environment so I hadn't come across that issue.

-Ted Allen

:


Unless your fields are fixed length, and the "/" is always in
the
same spot,
you will likely also need the len() and instr() functions.
Such
as:

Right([YourField],len([YourField])-instr([YourField],"/",1))


You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function.
Without
this your expression would error outside of the MS Access UI.

Jamie.
 
Hello, can I ask for one more variation? I'd like to pull the 3rd character
after the /. I'm getting the 3rd character plus everything that follows. I
only need that character.

Here's what I've got.

Special: Mid([Circuit_ID],InStr(3,[Circuit_ID],'/',3)+3)

How do I cut it off so nothing else displays but the 3rd character after the
/.

Thanks!
Mary
 
There is a third argument for the Mid function that tells the function how
many characters to select. So, if you just want one character:

Special: Mid([Circuit_ID],InStr(3,[Circuit_ID],'/',3)+3, 1)

--

Ken Snell
<MS ACCESS MVP>


Mary said:
Hello, can I ask for one more variation? I'd like to pull the 3rd
character
after the /. I'm getting the 3rd character plus everything that follows.
I
only need that character.

Here's what I've got.

Special: Mid([Circuit_ID],InStr(3,[Circuit_ID],'/',3)+3)

How do I cut it off so nothing else displays but the 3rd character after
the
/.

Thanks!
Mary
Ken Snell said:
You're welcome.
 
Hello again -

I have been using the format from Ken successfully until a new twist came up
today. Is there a way to make this an If/then statement.

Here is my current statement:
DESCR:
LTrim(Mid(Left([Description],InStr([Description],"(")-1),InStr([Description],":")+1))

I need to see everything after the : and before the (
In today's case, there is no ( so I just need to see everything after the :

I've used IIF statements, but not sure how to incorporate one into this
statement.

Thanks again!
Mary

Ken Snell said:
ahhh......ACCESS 97 doesn't contain that built-in function. So let's change
the expression, assuming that there is only the one : character in the
string:

ExtractedString = Mid(Left(OriginalString, InStr(OriginalString, ":") - 1),
InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>



Mary said:
Access 97

Ken Snell said:
Which version of ACCESS are you using?

--

Ken Snell
<MS ACCESS MVP>

Ken, I'm getting an "Undefined function, InStrRev" error, this is what
I
tried:

DESCRIPTION:
Mid(Left([DESCR],InStrRev([DESCR],":")-1),InStr([DESCR],"-")+1)

Thanks, Mary

:

Something like this, perhaps:

ExtractedString = Mid(Left(OriginalString, InStrRev(OriginalString,
":") -
1), InStr(OriginalString, "-") + 1)

--

Ken Snell
<MS ACCESS MVP>

Hello, I used Jamie's solution successfully, however, I'm wondering
if
there's a way to extract between to characters. The data I want to
extract
will always fall between "-" and ":". Right now I'm picking up
everything
after "-".

Thanks,
Mary

:

You're right Jamie, much cleaner solution. I forgot that the mid
function
defaults the length to the remainder of the string if ommitted.
Also,
good
point about the start pos in the Instr() function. I guess I only
use
it
in
Access environment so I hadn't come across that issue.

-Ted Allen

:


Unless your fields are fixed length, and the "/" is always in
the
same spot,
you will likely also need the len() and instr() functions.
Such
as:

Right([YourField],len([YourField])-instr([YourField],"/",1))


You could use just MID and INSTR e.g.

MID(MyTextCol,INSTR(1,MyTextCol,'/',1)+1)

Note the '1' used as the first argument to the INSTR function.
Without
this your expression would error outside of the MS Access UI.

Jamie.
 

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

Back
Top