A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Remove Certain String from Query Field



 
 
Thread Tools Display Modes
  #1  
Old November 25th, 2009, 05:24 PM posted to microsoft.public.access.queries
hadi
external usenet poster
 
Posts: 44
Default Remove Certain String from Query Field

Hello Experts,

I have a query with mulitple fields. one of them contains the names of the
projects our depatrment is working on. the name starts with a 4 digit number,
then an underscore, then a 4 or 5 digit number then another underscore then
the Name of the proejct itself. so the field looks like this
xxxx_xxxx_Project Name. I want to create an experssion that only shows the
Project Name part without the numbers or the underscores. the Problem i'm
having tis that the number of these digits vary from project to project. the
total number of characters can very between 10 12 so I can really use left,
mid or some of these other functions. Is there another way to do this?

thank you,

Hadi
  #2  
Old November 25th, 2009, 05:43 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Remove Certain String from Query Field

Try this --
Mid([YourField], InStrRev([YourField], "_")+1)

--
Build a little, test a little.


"Hadi" wrote:

Hello Experts,

I have a query with mulitple fields. one of them contains the names of the
projects our depatrment is working on. the name starts with a 4 digit number,
then an underscore, then a 4 or 5 digit number then another underscore then
the Name of the proejct itself. so the field looks like this
xxxx_xxxx_Project Name. I want to create an experssion that only shows the
Project Name part without the numbers or the underscores. the Problem i'm
having tis that the number of these digits vary from project to project. the
total number of characters can very between 10 12 so I can really use left,
mid or some of these other functions. Is there another way to do this?

thank you,

Hadi

  #3  
Old November 25th, 2009, 05:45 PM posted to microsoft.public.access.queries
fredg
external usenet poster
 
Posts: 4,386
Default Remove Certain String from Query Field

On Wed, 25 Nov 2009 09:24:01 -0800, Hadi wrote:

Hello Experts,

I have a query with mulitple fields. one of them contains the names of the
projects our depatrment is working on. the name starts with a 4 digit number,
then an underscore, then a 4 or 5 digit number then another underscore then
the Name of the proejct itself. so the field looks like this
xxxx_xxxx_Project Name. I want to create an experssion that only shows the
Project Name part without the numbers or the underscores. the Problem i'm
having tis that the number of these digits vary from project to project. the
total number of characters can very between 10 12 so I can really use left,
mid or some of these other functions. Is there another way to do this?

thank you,

Hadi


Note: In the future, when posting to these newsgroups, it would be in
your best interest to include your Access version number. It may make
a difference in the response. For example, what may work in Access
2007 may not work in previous versions, and vise versa.

if your version of Access has the InStrRev() function you can use:

ProjName:Mid([FieldName],InStrRev([FieldName],"_")+1)

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #4  
Old November 25th, 2009, 05:53 PM posted to microsoft.public.access.queries
hadi
external usenet poster
 
Posts: 44
Default Remove Certain String from Query Field

Karl,

this works except that Project Name also might an underscore somewhere in
it. is there a way to pick up everything to the left of the SECOND underscore?

"KARL DEWEY" wrote:

Try this --
Mid([YourField], InStrRev([YourField], "_")+1)

--
Build a little, test a little.


"Hadi" wrote:

Hello Experts,

I have a query with mulitple fields. one of them contains the names of the
projects our depatrment is working on. the name starts with a 4 digit number,
then an underscore, then a 4 or 5 digit number then another underscore then
the Name of the proejct itself. so the field looks like this
xxxx_xxxx_Project Name. I want to create an experssion that only shows the
Project Name part without the numbers or the underscores. the Problem i'm
having tis that the number of these digits vary from project to project. the
total number of characters can very between 10 12 so I can really use left,
mid or some of these other functions. Is there another way to do this?

thank you,

Hadi

  #5  
Old November 25th, 2009, 05:58 PM posted to microsoft.public.access.queries
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Remove Certain String from Query Field

You can nest it. Try this --
Mid(Mid([YourField], InStr([YourField], "_")+1), InStr(Mid([YourField],
InStr([YourField], "_")+1), "_")+1)

--
Build a little, test a little.


"Hadi" wrote:

Karl,

this works except that Project Name also might an underscore somewhere in
it. is there a way to pick up everything to the left of the SECOND underscore?

"KARL DEWEY" wrote:

Try this --
Mid([YourField], InStrRev([YourField], "_")+1)

--
Build a little, test a little.


"Hadi" wrote:

Hello Experts,

I have a query with mulitple fields. one of them contains the names of the
projects our depatrment is working on. the name starts with a 4 digit number,
then an underscore, then a 4 or 5 digit number then another underscore then
the Name of the proejct itself. so the field looks like this
xxxx_xxxx_Project Name. I want to create an experssion that only shows the
Project Name part without the numbers or the underscores. the Problem i'm
having tis that the number of these digits vary from project to project. the
total number of characters can very between 10 12 so I can really use left,
mid or some of these other functions. Is there another way to do this?

thank you,

Hadi

  #6  
Old November 25th, 2009, 06:13 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Remove Certain String from Query Field

ASSUMPTION: There is ALWAYS two underscores.

Mid(ProjectField,Instr(Instr(1,ProjectField,"_")+1 ,ProjectField,"_")+1)

You can test before you execute the expression

IIF(ProjectField Like "*_*_*",
Mid(ProjectField,Instr(Instr(1,ProjectField,"_")+1 ,ProjectField,"_")+1)
,ProjectField)

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Hadi wrote:
Hello Experts,

I have a query with mulitple fields. one of them contains the names of the
projects our depatrment is working on. the name starts with a 4 digit number,
then an underscore, then a 4 or 5 digit number then another underscore then
the Name of the proejct itself. so the field looks like this
xxxx_xxxx_Project Name. I want to create an experssion that only shows the
Project Name part without the numbers or the underscores. the Problem i'm
having tis that the number of these digits vary from project to project. the
total number of characters can very between 10 12 so I can really use left,
mid or some of these other functions. Is there another way to do this?

thank you,

Hadi

  #7  
Old November 25th, 2009, 07:19 PM posted to microsoft.public.access.queries
hadi
external usenet poster
 
Posts: 44
Default Remove Certain String from Query Field

Works great. Thank you Karl

"KARL DEWEY" wrote:

You can nest it. Try this --
Mid(Mid([YourField], InStr([YourField], "_")+1), InStr(Mid([YourField],
InStr([YourField], "_")+1), "_")+1)

--
Build a little, test a little.


"Hadi" wrote:

Karl,

this works except that Project Name also might an underscore somewhere in
it. is there a way to pick up everything to the left of the SECOND underscore?

"KARL DEWEY" wrote:

Try this --
Mid([YourField], InStrRev([YourField], "_")+1)

--
Build a little, test a little.


"Hadi" wrote:

Hello Experts,

I have a query with mulitple fields. one of them contains the names of the
projects our depatrment is working on. the name starts with a 4 digit number,
then an underscore, then a 4 or 5 digit number then another underscore then
the Name of the proejct itself. so the field looks like this
xxxx_xxxx_Project Name. I want to create an experssion that only shows the
Project Name part without the numbers or the underscores. the Problem i'm
having tis that the number of these digits vary from project to project. the
total number of characters can very between 10 12 so I can really use left,
mid or some of these other functions. Is there another way to do this?

thank you,

Hadi

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:44 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.