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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Search number in a string



 
 
Thread Tools Display Modes
  #1  
Old August 26th, 2006, 02:31 AM posted to microsoft.public.access.forms
Anna
external usenet poster
 
Posts: 66
Default Search number in a string

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You

  #2  
Old August 26th, 2006, 02:38 AM posted to microsoft.public.access.forms
John Vinson
external usenet poster
 
Posts: 4,033
Default Search number in a string

On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You


A criterion of

LIKE "*[0-9]*"

will return records where the field contains a digit anywhere within
the string.

To blindly remove all digits from a string, without tripping an error
when there are none, you can use a snarky nested Replace() function:

Replace(Replace(Replace(Replace(Replace(Replace(Re place(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5","")," 6",""),"7",""),"8",""),"9","")


John W. Vinson[MVP]
  #3  
Old August 26th, 2006, 02:50 AM posted to microsoft.public.access.forms
J. Goddard
external usenet poster
 
Posts: 159
Default Search number in a string

How does your string get its values? If users enter it in a form, you
can use the mask property of the field to accept only alphabetic
characters (if that is what you need in the string)

John


John Vinson wrote:
On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:


How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You



A criterion of

LIKE "*[0-9]*"

will return records where the field contains a digit anywhere within
the string.

To blindly remove all digits from a string, without tripping an error
when there are none, you can use a snarky nested Replace() function:

Replace(Replace(Replace(Replace(Replace(Replace(Re place(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5","")," 6",""),"7",""),"8",""),"9","")


John W. Vinson[MVP]


  #4  
Old August 26th, 2006, 04:42 AM posted to microsoft.public.access.forms
Anna
external usenet poster
 
Posts: 66
Default Search number in a string

Thanks for reply. I parse values from a textfile so there is nothing
with the database. Some times text file contains subject with numbers
which i have to remove during parsing.

J. Goddard wrote:
How does your string get its values? If users enter it in a form, you
can use the mask property of the field to accept only alphabetic
characters (if that is what you need in the string)

John


John Vinson wrote:
On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:


How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You



A criterion of

LIKE "*[0-9]*"

will return records where the field contains a digit anywhere within
the string.

To blindly remove all digits from a string, without tripping an error
when there are none, you can use a snarky nested Replace() function:

Replace(Replace(Replace(Replace(Replace(Replace(Re place(Replace(Replace(Replace([field],"0",""),"1",""),"2",""),"3",""),"4",""),"5","")," 6",""),"7",""),"8",""),"9","")


John W. Vinson[MVP]


  #5  
Old August 26th, 2006, 07:27 AM posted to microsoft.public.access.forms
John Nurick
external usenet poster
 
Posts: 492
Default Search number in a string

One approach is to use the rgxReplace() function at
http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm
with a pattern that catches digits and any spaces that precede them,
e.g.:

Dim S as String
S = "Name Change Form 23124"
S = rgxReplace(S, "\s*\d+", "")
Debug.Print S

Name Change Form





On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
  #6  
Old August 26th, 2006, 09:55 PM posted to microsoft.public.access.forms
Anna
external usenet poster
 
Posts: 66
Default Search number in a string

This function works fine only one thing is some times the value is:
Subject
Name Change Form - 23124
Subject = rgxReplace(Subject, "\s*\d+", "")

This function returns the value
Name Change Form -

Does this possible that it removes the hypen sign too

Thank You

John Nurick wrote:
One approach is to use the rgxReplace() function at
http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm
with a pattern that catches digits and any spaces that precede them,
e.g.:

Dim S as String
S = "Name Change Form 23124"
S = rgxReplace(S, "\s*\d+", "")
Debug.Print S

Name Change Form





On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.


  #7  
Old August 26th, 2006, 10:10 PM posted to microsoft.public.access.forms
John Nurick
external usenet poster
 
Posts: 492
Default Search number in a string

Hi Anna,

Try it with this regular expression
\s*-?\s*\d+

Each \s* matches zero or more spaces (or tabs), and the -? matches a
hyphen if there is one (zero or one hyphen).

On 26 Aug 2006 13:55:53 -0700, "Anna" wrote:

This function works fine only one thing is some times the value is:
Subject
Name Change Form - 23124
Subject = rgxReplace(Subject, "\s*\d+", "")

This function returns the value
Name Change Form -

Does this possible that it removes the hypen sign too

Thank You

John Nurick wrote:
One approach is to use the rgxReplace() function at
http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm
with a pattern that catches digits and any spaces that precede them,
e.g.:

Dim S as String
S = "Name Change Form 23124"
S = rgxReplace(S, "\s*\d+", "")
Debug.Print S

Name Change Form





On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
  #8  
Old August 26th, 2006, 10:44 PM posted to microsoft.public.access.forms
Anna
external usenet poster
 
Posts: 66
Default Search number in a string

Thanks a loot you are very sweet. I would be greatfull if you please
tell me how you make this expression or any link/tutorial by which i
can get this expression by myself.

Thanks again,

Anna.

John Nurick wrote:
Hi Anna,

Try it with this regular expression
\s*-?\s*\d+

Each \s* matches zero or more spaces (or tabs), and the -? matches a
hyphen if there is one (zero or one hyphen).

On 26 Aug 2006 13:55:53 -0700, "Anna" wrote:

This function works fine only one thing is some times the value is:
Subject
Name Change Form - 23124
Subject = rgxReplace(Subject, "\s*\d+", "")

This function returns the value
Name Change Form -

Does this possible that it removes the hypen sign too

Thank You

John Nurick wrote:
One approach is to use the rgxReplace() function at
http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm
with a pattern that catches digits and any spaces that precede them,
e.g.:

Dim S as String
S = "Name Change Form 23124"
S = rgxReplace(S, "\s*\d+", "")
Debug.Print S

Name Change Form





On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.


  #9  
Old August 27th, 2006, 08:31 AM posted to microsoft.public.access.forms
John Nurick
external usenet poster
 
Posts: 492
Default Search number in a string


On this page http://www.j.nurick.dial.pipex.com/Code/index.htm and on
the one I originally referred you to, there's a link "More about regular
expressions". That will take you to a page with links to information on
using regular expressions.

On 26 Aug 2006 14:44:39 -0700, "Anna" wrote:

Thanks a loot you are very sweet. I would be greatfull if you please
tell me how you make this expression or any link/tutorial by which i
can get this expression by myself.

Thanks again,

Anna.

John Nurick wrote:
Hi Anna,

Try it with this regular expression
\s*-?\s*\d+

Each \s* matches zero or more spaces (or tabs), and the -? matches a
hyphen if there is one (zero or one hyphen).

On 26 Aug 2006 13:55:53 -0700, "Anna" wrote:

This function works fine only one thing is some times the value is:
Subject
Name Change Form - 23124
Subject = rgxReplace(Subject, "\s*\d+", "")

This function returns the value
Name Change Form -

Does this possible that it removes the hypen sign too

Thank You

John Nurick wrote:
One approach is to use the rgxReplace() function at
http://www.j.nurick.dial.pipex.com/C...rgxReplace.htm
with a pattern that catches digits and any spaces that precede them,
e.g.:

Dim S as String
S = "Name Change Form 23124"
S = rgxReplace(S, "\s*\d+", "")
Debug.Print S

Name Change Form





On 25 Aug 2006 18:31:10 -0700, "Anna" wrote:

How to check a number in a string. Some times i have values contains
numbers some times dont. I try split but it gives error when there is
no number in the string. What i need is to check the string if it not
contains numbers than ok otherwise i have to remove the number from the
string

Subject
Name Change Form
Name Change Form 23124

Thank You

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.


--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 




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 05:11 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.