473,396 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help wanted Query Criteria

Bob
Hullo Everybody

What is the expression that I need to use to run a query that returns only records with exactly 10
NUMERIC characters CONTAINED in a field called "ProductNumber" There may sometimes be other things
in the field. This does not matter. I am looking for the records with a product field that CONTAINS
somewhere in the text 10 NUMBERs.

For Instance:

(1) I want these records (10 NUMERIC)
9876765432
0987665576
5464663557
7845673456

(2) I DO NOTwant these records (10 characters but some are NOT NUMERIC
PE9875632Q
ZR0987576U
JH5463557T
RT7873456V

(3) I DO NOTwant these records EITHER (Only 9 NUMERIC)
876765432
987665576
464663557
784567345

I have tried LIKE "???????????*" but that did not work

Thanks

Smiley Bob

Nov 12 '05 #1
6 1738
"Bob" <sm*******@hotmail.com> wrote in message
news:6h********************************@4ax.com...
Hullo Everybody

What is the expression that I need to use to run a query that returns only records with exactly 10 NUMERIC characters CONTAINED in a field called "ProductNumber" There may sometimes be other things in the field. This does not matter. I am looking for the records with a product field that CONTAINS somewhere in the text 10 NUMBERs.

Do we eliminate records that cannot be converted to numbers? If so the
solution is easy:

SELECT * FROM products
WHERE Len(ProductNumber)=10
AND IsNumeric(ProductNumber) = True

but if you need to search for the existence of 10 numeric chacters within a
string that may also contain non-numeric charctares it's a bit more
difficult. I think you need a VBA function for that.

Nov 12 '05 #2
Add a temp column to your query grid. This column will be populated
with only a string of 10 numeric chars. The way you will populate this
column is by writing a function as follows which will take values from
your actual column in question. The function will parse the values for
each row, and if there is a string containing 10 consecutive digits that
value will be added to the temp column otherwise the function returns
"".

In the field name add this:

temp:getNum(yourActualfieldnamehere)

Under the criteria for temp add:

<> ""

This will yield a resultset where only rows that contain values from
your actual column that are 10 consecutive numeric chars.

Here is a function that does this:

'******************************************
Function getNum(x As Variant) As Variant
Dim i As Integer, j As Integer, k As Integer, y As Variant
For i = 1 To Len(x)
y = Mid(x, i, 1)
If j = 0 And IsNumeric(y) Then j = i 'beginning of number
If j > 0 And Not IsNumeric(y) Then
k = i - 1
Exit For
End If
If j > 0 And i - j + 1 = 10 Then
k = i
Exit For
End If
Next
If k - j - 9 = 0 Then getNum = Mid(x, j, 10)
End Function
'************************************************* ***

It isn't pretty, but it is functional, and Free! This function will
return values like these

1231231234, 1234567890

from xx1231231234 or 1231231234xxx or aaa1234567890kkk

and will not return values like these

123123123 (only 9 digits)
or 1 231231234 (a space breaks the continuity)
or xxx12312312x3 (not 10 consecutive digits)

based on your specifications. You can place this function in a standard
code module (not a form code module) so that the query can access it.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
Bob
On 21 Apr 2004 21:37:29 GMT, Rich P <rp*****@aol.com> wrote:
Add a temp column to your query grid. This column will be populated
with only a string of 10 numeric chars. The way you will populate this
column is by writing a function as follows which will take values from
your actual column in question. The function will parse the values for
each row, and if there is a string containing 10 consecutive digits that
value will be added to the temp column otherwise the function returns
"".

In the field name add this:

temp:getNum(yourActualfieldnamehere)

Under the criteria for temp add:

<> ""

This will yield a resultset where only rows that contain values from
your actual column that are 10 consecutive numeric chars.

Here is a function that does this:

'******************************************
Function getNum(x As Variant) As Variant
Dim i As Integer, j As Integer, k As Integer, y As Variant
For i = 1 To Len(x)
y = Mid(x, i, 1)
If j = 0 And IsNumeric(y) Then j = i 'beginning of number
If j > 0 And Not IsNumeric(y) Then
k = i - 1
Exit For
End If
If j > 0 And i - j + 1 = 10 Then
k = i
Exit For
End If
Next
If k - j - 9 = 0 Then getNum = Mid(x, j, 10)
End Function
'************************************************ ****

It isn't pretty, but it is functional, and Free! This function will
return values like these

1231231234, 1234567890

from xx1231231234 or 1231231234xxx or aaa1234567890kkk

and will not return values like these

123123123 (only 9 digits)
or 1 231231234 (a space breaks the continuity)
or xxx12312312x3 (not 10 consecutive digits)

based on your specifications. You can place this function in a standard
code module (not a form code module) so that the query can access it.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


That works spot on. Well almost.

There are a number of records that have Null data, and these throw up a fault that stops the program
running, and opens the code editor, which give the user palpitations.

That code is a bit complicated so if anyone knows the answer I'd be grateful.

Thanks to all that have helped.

Smiley Bob

Nov 12 '05 #4
Ah yes, the old "Invalid use of Null" error. Try this one:

Function getNum(x As Variant) As Variant
Dim i As Integer, j As Integer, k As Integer, y As Variant
If Not IsNull(x) Then
For i = 1 To Len(x)
y = Mid(x, i, 1)
If j = 0 And IsNumeric(y) Then j = i 'beginning of num
If j > 0 And Not IsNumeric(y) Then
k = i - 1
Exit For
End If
If j > 0 And i - j + 1 = 10 Then
k = i
Exit For
End If
Next
If k - j - 9 = 0 Then getNum = Mid(x, j, 10)
End If
End Function

In this version I check to see if the value passed to the function is
null or not. If it is not null, then we process the value. If there is
no value (value is null - note: value will never = equal Null - no such
thing - IsNull means there is no value it does not mean = 0 or = "").
If there is no value, then the function returns no value, Null. This
should do the trick. Good thing this isn't DotNet. DotNet would have
been way less friendly with this function (variants are evil)---:).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5
Bob
On 22 Apr 2004 16:07:17 GMT, Rich P <rp*****@aol.com> wrote:
Ah yes, the old "Invalid use of Null" error. Try this one:

Function getNum(x As Variant) As Variant
Dim i As Integer, j As Integer, k As Integer, y As Variant
If Not IsNull(x) Then
For i = 1 To Len(x)
y = Mid(x, i, 1)
If j = 0 And IsNumeric(y) Then j = i 'beginning of num
If j > 0 And Not IsNumeric(y) Then
k = i - 1
Exit For
End If
If j > 0 And i - j + 1 = 10 Then
k = i
Exit For
End If
Next
If k - j - 9 = 0 Then getNum = Mid(x, j, 10)
End If
End Function

In this version I check to see if the value passed to the function is
null or not. If it is not null, then we process the value. If there is
no value (value is null - note: value will never = equal Null - no such
thing - IsNull means there is no value it does not mean = 0 or = "").
If there is no value, then the function returns no value, Null. This
should do the trick. Good thing this isn't DotNet. DotNet would have
been way less friendly with this function (variants are evil)---:).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


That did it. Thanks

I have learned from this

Regards Smiley Bob
Nov 12 '05 #6
Bob
<Grin>

Now the client is asking for another query that does the opposite of this
ie finds all the records that DON'T have 10 numeric characters and of course have
no Nulls

I need a drink

Smiley Bob

On Thu, 22 Apr 2004 17:50:43 +0100, Bob <sm*******@hotmail.com> wrote:
On 22 Apr 2004 16:07:17 GMT, Rich P <rp*****@aol.com> wrote:
Ah yes, the old "Invalid use of Null" error. Try this one:

Function getNum(x As Variant) As Variant
Dim i As Integer, j As Integer, k As Integer, y As Variant
If Not IsNull(x) Then
For i = 1 To Len(x)
y = Mid(x, i, 1)
If j = 0 And IsNumeric(y) Then j = i 'beginning of num
If j > 0 And Not IsNumeric(y) Then
k = i - 1
Exit For
End If
If j > 0 And i - j + 1 = 10 Then
k = i
Exit For
End If
Next
If k - j - 9 = 0 Then getNum = Mid(x, j, 10)
End If
End Function

In this version I check to see if the value passed to the function is
null or not. If it is not null, then we process the value. If there is
no value (value is null - note: value will never = equal Null - no such
thing - IsNull means there is no value it does not mean = 0 or = "").
If there is no value, then the function returns no value, Null. This
should do the trick. Good thing this isn't DotNet. DotNet would have
been way less friendly with this function (variants are evil)---:).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


That did it. Thanks

I have learned from this

Regards Smiley Bob


Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
2
by: mark | last post by:
I've been working on an Access 2000 database for a couple of weeks now. I took a course in access about a year ago, a crash course, and I learned a ton, but I didn't touch Access for the year since...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
5
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
6
by: Megan | last post by:
Hi everybody- I'm trying to use a checkbox to control whether or not a date field in a query "Is Null" or "Is Not Null." I have 2 date fields: InDate and OutDate. If there is an OutDate, then...
5
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
7
by: John | last post by:
hi, i have created a search form, and i want to search for a specific item in a field. e.g. i have a field called colour, which has record1 = 'red, blue, green' and another record2 = 'red' ...
3
by: mcmahonb | last post by:
Hey people... I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my...
0
by: jon | last post by:
Hi there, I'm brand new to Access and may be trying to do too much too soon, but I wanted to get some expert advice on how the best way to go about what I am trying to accomplish would be. I...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.