|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (9 bit)
|
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
|
|
|
|
|
|
#2 |
|
Member (10 bit)
|
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)' |
|
|
|
|
|
#3 |
|
Professional gadfly
|
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. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|