 |
 |

03-28-2004, 09:24 PM
|
|
Newcomer
|
|
Join Date: Feb 2004
Posts: 15
|
|
Searching numeric values
|
I am currently writing a organizer type program that has 27 buttons at the top (one for each letter in the alphabet and one for #) in an array. When one of the buttons is clicked, it goes through the database and returns all results that start with the letter that was clicked. Everything for the letters works great but where I am stuck is the searching of numbers (0-9). I don't really want to do a search for every number. I search for the letters as follows:
Char = Index + 64 'Calculates the character code for the letter of the button
With DBConnect.rsGames
.Sort = "Title ASC"
If Not .BOF Then .MoveFirst
.Find "Title like '" & Chr$(Char) & "*'"
Now how would I go about using this to search for ANY number and not specific ones
|
|

03-29-2004, 01:42 AM
|
 |
Contributor
|
|
Join Date: Apr 2002
Location: brgy Ginebra
Posts: 449
|
|
|
you could do range search... where number between this and that...
|
|

03-29-2004, 02:00 AM
|
|
Junior Contributor
|
|
Join Date: Feb 2004
Location: Southampton, UK
Posts: 335
|
|
|
If this is sqlserver (I don't know about Access) you can use regular expressions:
.Find "Title like '[0-9]%'"
|
|

03-29-2004, 06:32 AM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
Instead of using the Find method, I would simply use SQL. You could write an SQL SELECT statement that finds all numbers or values LIKE your condition..you would need to use wildcards within your SQL statement (% for ADO, * for DAO).
But if your heart is set on the Find method you can use it with Access...the .Find method should look like this:
Code:
rs.Open sSQL, cn, adOpenKeySet, adLockOptimistic, adCmdText
rs.Find "field1 LIKE 'hello'%"
You need to use a valid field within the opened recordset.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-29-2004, 06:37 AM
|
|
Junior Contributor
|
|
Join Date: Feb 2004
Location: Southampton, UK
Posts: 335
|
|
|
his problem is not using a wildcard search, It is to find records starting with a numeric character.
|
|

03-29-2004, 06:47 AM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
Use a function, such as isnumeric  . If we need to check BEYOND the first character, we can write a function that loop until Len() of the recordset value finding ANY numerical characters. But then, what is the final result supposed to be? Say I find that a value starts with a numeric character, then what? If it starts with a number, are we adding it to a Grid control, displaying it somewhere. Something like this:
Code:
rs.open sSQL, cn, adOpenKeySet, adLockOptistic, adCmdText
While rs.EOF = False
If IsNumeric(Left(rs.Fields("myField").value, 1)) Then
[do something]
End If
rs.moveNext
Wend
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-29-2004, 06:57 AM
|
|
Junior Contributor
|
|
Join Date: Feb 2004
Location: Southampton, UK
Posts: 335
|
|
Quote:
|
Originally Posted by MKoslof
Use a function, such as isnumeric
|
You can't put isnumeric into sql  . Read snoopy's problem - he wants to retrieve records that START with a numeric character (not just contain a numeric value) when they press the "#" button as opposed to a button with A-Z on it. e.g. "99 red balloons"
this is done by using regular expression searches:
1) object method: .Find "Title like '[0-9]%'"
2) Sql string: select * from table where Title like '[0-9]%'
|
|

03-29-2004, 07:00 AM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
Actually, no. YES you can put ISNUMERIC in an SQL Statement...have you tried it before?
And point two, his example uses the .find method, which implies he is OPENING a recordset and SEARCHING through it...something that is exactly the same as using a While loop and incrementing through the recordset.
But I appreciate your input and questions 
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-29-2004, 08:03 AM
|
|
Newcomer
|
|
Join Date: Feb 2004
Posts: 15
|
|
Still not working
|
Thanx to all those that replied. I have tried some of the solutions posted here and am still unable to get this thing to work. As I am not very familiar with SQL statements, I would like to use another solution. Maybe I can explain a bit better. When you click the button for #, it goes to the database and finds the first result with a number as the first character. Once the result is found, it posts all the information on the form. Then there are 2 buttons (Next and previous) which can be used to search for more records that begin with a number. The problem I have is finding the records that begin with a number. The database field that I'm searching is "Title" and has entries like this:
21 Grams
2 Fast 2 Furious
3 Kings
Ace Ventura
Bad Boys
ect...
The database has over 800 records and growing so to loop through each record to see if it is numeric sounds like a lot of extra processing. Reading through the help files I found 2 other commands that might help (Seek and Filter) but haven't got them to work either
|
|

03-29-2004, 08:06 AM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
|
So use SQL for this...is this an Access mdb, try this:
(*return all records where the field in question STARTS with a number)
SELECT *
FROM Table1
WHERE IsNumeric(Left(field1,1))
The only *other solution* is to open the recordset and test each record, something I also showed a brief example of. There really is no other way to do this because you need to evaluate the records.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-29-2004, 08:16 AM
|
|
Junior Contributor
|
|
Join Date: Feb 2004
Location: Southampton, UK
Posts: 335
|
|
You cannot use .find unless you load the result set with the whole table in the first place. What you should do is (like I have said before) is use regular expressions. Every time a user presses a button re-run a SQL search with new criteria:
if the user presses a Alpha-character button run this sql
Code:
SqlString = "SELECT * FROM TableName WHERE (((Title) Like '" & Chr$(Char) & "*'"
If the user presses the "#" button use this sql
Code:
"SELECT * FROM TableName WHERE (((Title) Like '[0-9]*'))"
This will work in access and SQLserver; If you don't believe me then run this sql in Northwind.mdb:
Code:
SELECT *
FROM Customers
WHERE (((Customers.Address) Like "[0-9]*"));
|
|

03-29-2004, 08:18 AM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
|
No, if Access, just test for ISNUMERIC. If SQL Server, you could use a CASE within your SELECT to test for the ISNUMERIC function, which returns 0 or 1 in SQL Server. If your condition is simply to find any value that starts with a number, the LIKE search is not needed.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-29-2004, 08:21 AM
|
|
Newcomer
|
|
Join Date: Feb 2004
Posts: 15
|
|
SQL Statement
|
If I were to use that SQL statement would it return the first result it finds with a number at the beginning and if so how would I tell it to find the next record with a number at the beginning when they press the "Next" button?
|
|

03-29-2004, 08:24 AM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
|
If you only want the first instance you still need to open the recordset..as I have stated and AndyH has stated. Basically, use the ISNUMERIC() call to open a recordset with only numeric characters as the first character. Then, you use can the .Find method, the .FindFirst method or loop until EOF to bring in specific values.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-29-2004, 08:31 AM
|
|
Newcomer
|
|
Join Date: Feb 2004
Posts: 15
|
|
Resolved
|
Thanx to all that have posted so quickly. I got it working with Isnumeric.
|
|

03-29-2004, 08:35 AM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
|
No problem...good luck to you!
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|