-
Can anyone help me with making a search function?
I'm using a Access 2000 db with vb6.
My Project is: I'm gonna make a program for a video-rental-store, with posibility to search on customers name and Movie-title. Is this any help for you? Hopeing for an answer!
-
What do you want help with? Setting up the connection to the db, creating tables, writing vb-code?
-
you have to use ADO and sql
Code:
'assuming your ado recordset is called RS and connection is called conn
dim SQLStatement as string
If SearchByCustomer = True then
dim CustomerName as string
CustomerName = txtcustomer.text
SQLStatement = "SELECT * FROM MyTable WHERE CustomerName = '" & CustomerName & "'"
elseif SearchByTitle then
Dim VideoTitle as string
VideoTitle = txtvideotitle.text
SQLStatement = "SELECT * FROM MyTable WHERE VideoTitle = '" & VideoTitle & "'"
end if
RS.Open SQLStatement, conn
with rs
if .eof then
msgbox "nothing found"
else
'do what ever you want with whts found
end if
.close
end with
i hope that helped
if you need more help let me know
-
Use LIKE instead:
SELECT * FROM MyTable WHERE CustomerName LIKE '"%" & CustomerName & "%"'"
If you typed in "Ander" the statement will find every customer which name contains Ander, for example Andersson, Anderlecht and so on :-)
I´m not that sure how to use the '%'...
-
assumption was based on he wanted to check for exact
you use % by typing it at the beganning and end of the string
like this
videotitle LIKE '%kova%'
have fun sqling
-
Remember LIKE is a lot slower than '='