943,890 Members | Top Members by Rank

Ad:
Nov 10th, 2005
0

Searching for a string in an access database

Expand Post »
Hi there,

I have a system built in VB_6 professional which reads from an access database.
I need to search for a specific record using a word or short description entered by the user. This will link to the DESCRIPTION field in the database itself. Not being case sensitive would be a bonus.

Does anybody have any sample code for such a function? or does anybody know where i could find such code?

Many thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
robbie_j0 is offline Offline
4 posts
since Oct 2005
Mar 27th, 2006
0

Re: Searching for a string in an access database

do it though your SQL query. I havent used an Access SQL query in years, but it might be similar to:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim searchText as String
  2. Dim sqlQuery as String
  3. searchText = searchDescription.Text
  4. sqlQuery = "SELECT * FROM `whatever_table` WHERE `description` LIKE `%" & searchText & "%' LIMIT 10;"

Then execute the query with searchText.
Reputation Points: 10
Solved Threads: 0
Light Poster
calcop is offline Offline
27 posts
since Oct 2005
Mar 27th, 2006
0

Re: Searching for a string in an access database

I believe Access does not have the LIMIT keyword, and that is only an extension specific to MySQL. MS SQL Server uses TOP but I don't think Access has this function. Also, Access and MS SQL Server uses square brackets ([]) to delimit its variable names, while MySQL uses the backtick (`). Other than these issues, the LIKE operator would settle your string searching needs.

For case-insensitivity, first of all, I do not know if this function is available in VB because all I've used is VB.NET. Note the underlined portions:
Dim searchText as String
Dim sqlQuery as String
searchText = searchDescription.Text
sqlQuery = "SELECT * FROM [whatever_table] WHERE TOLOWER([description]) LIKE `%" & searchText.ToLower() & "%';"
When you set both the field you are matching with and the match text to lowercase (or uppercase), it is equivalent to a case-insensitive match, albeit the possible inefficiency of matching long strings of opposite-cased text.

You might want to take a look at this two posts for some issues related to this:
http://www.daniweb.com/techtalkforums/post200141-5.html
http://www.daniweb.com/techtalkforums/post200190-9.html

Hope this helps
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
AstroNox is offline Offline
50 posts
since Mar 2006
Mar 27th, 2006
0

Re: Searching for a string in an access database

Ok, this is a vb 4, 5, 6 forum, not a vb.net forum. Should you be looking for that forum, you can find it here: http://www.daniweb.com/techtalkforums/forum58.html. var.tolower() is a .net method, and is not available in vb6. Let's try to keep related information grouped in their respective forums.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Mar 27th, 2006
0

Re: Searching for a string in an access database

I'm sorry but I didn't know that ToLower() is a VB.NET specific function. You see, I've never programmed in VB4/5/6 before, but I had done VB.NET and VBA so I thought I might be able to share something useful. Just trying to help but I'll keep that in mind next time. Thanks!
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
AstroNox is offline Offline
50 posts
since Mar 2006
Mar 27th, 2006
0

Re: Searching for a string in an access database

We appreciate all the help we can get, certainly, I just want to avoid having people trying to build something in one language get further complicated by examples for another.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: nested joins, from mdb. Possible?
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How do I program a multi-menu application?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC