Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 06-24-2002, 04:02 AM   #1
Member (9 bit)
 
Join Date: Dec 2001
Location: US
Posts: 468
Send a message via AIM to wilbasket23 Send a message via Yahoo to wilbasket23
Smile Question about wildcard charachters

hello everyone. can anyone help me. currently i am writing a seraching utilty which you can serach the database to find a particular record. but the problem is how can i accept the user input as well as the wildcard character like the space and etc. i am having trouble writing it using Visual Basic in Access. Can anyone help me or know any web sites that have good tutorial on Viaual Basic in Access(VBA). please help me out thank You
wilbasket23 is offline   Reply With Quote
Old 06-25-2002, 08:51 AM   #2
Member (10 bit)
 
Join Date: Apr 2001
Location: Michigan
Posts: 850
Send a message via ICQ to HackinCowboy
You can do an INSTR to search the input for certain characters. You can also do a TRIM and that will remove any extra spaces at beginning or end. After you do that just query the database like this:
Code:
SELECT * FROM database WHERE (field) LIKE '(user input)'
HackinCowboy is offline   Reply With Quote
Old 06-25-2002, 09:01 AM   #3
Professional gadfly
 
doctorgonzo's Avatar
 
Join Date: Jan 2002
Location: Minneapolis, MN
Posts: 6,364
Send a message via MSN to doctorgonzo
Do it just like HackinCowboy said, with wildcard characters inside the quotes. So if you want to search for all first names starting with "Johns", then write it like this:

SELECT * FROM People WHERE LastName LIKE 'Johns*'

If you want to search a field for text anywhere in that field, use two asterisks:

SELECT * FROM People WHERE LastName LIKE '*Johns*'

If the text you are searching for contains single quotes, then that won't work (for example, if you are searching for last names starting with "O'Lea" Then, you can use percent signs to surround the parameter:

SELECT * FROM People WHERE LastName LIKE %O'Lea*%

You could also use double quotes (Chr$(34)).

What I usually do is something like this. If txtInput is a text box that contains the user input, I do this:

strRec = "SELECT * FROM tblPeople WHERE strLastName LIKE '*" & Trim(Me.txtInput.Value) & "*';"

Then open a recordset using strRec as the source.
doctorgonzo is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:19 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2