|
-
Nov 21st, 2007, 10:25 AM
#1
Thread Starter
Lively Member
[RESOLVED] Search and Sort Question
VB6, Excel database, and I am not that good at these strings
I have a sql string which pulls all data from an employee directory db on startup. I get every listing in the db for each employee.
In a textbox_change routine for the first name, I have a sql string as follows:
Code:
strSQL = "SELECT FirstName" _
& " , LastName" _
& " , Dept" _
& " , Sub" _
& " , Loc" _
& " , Ext" _
& " , EmpID" _
& " FROM [mytable$] " _
& " WHERE FirstName='" & txt_First.Text & "'" _
& " ORDER BY LastName" _
& " , FirstName"
Problem is when I start typing in the textbox, it does exactly what it says it does and not what I want it to do.
What I want is like an auto complete. When I type the entire listings that get shown in a listview need to decrease until I have finished typing. I need something like a wild card in there.
& " WHERE FirstName='" & txt_First.Text & "*'" _
what do I need here?
-
Nov 21st, 2007, 10:39 AM
#2
Re: Search and Sort Question
To use a wildcard you need to use Like instead of = , eg:
Code:
& " WHERE FirstName Like '" & txt_First.Text & "*'" _
Note however that * (and ? for a single character) might not be the wildcard - as the standard is actually % (and _ ).
-
Nov 21st, 2007, 10:52 AM
#3
Thread Starter
Lively Member
Re: Search and Sort Question
OK.. I got it. Kinda threw me off but this works like I was wanting.
Thanks for your help!
Code:
& " WHERE FirstName Like'" & txt_First.Text & "%'" _
-
Nov 21st, 2007, 11:35 AM
#4
Thread Starter
Lively Member
Re: [RESOLVED] Search and Sort Question
Even though it is resolved, one last question. (Same topic)
How do you add more than one where statement.
Say I want something like this:
Code:
strSQL = "SELECT FirstName" _
& " , LastName" _
& " , Dept" _
& " , Sub" _
& " , Loc" _
& " , Ext" _
& " , EmpID" _
& " FROM [mytable$] " _
& " WHERE FirstName Like'" & txt_First.Text & "%'" _
& " , LastName Like'" & txt_Last.Text & "%'" _
& " ORDER BY LastName" _
& " , FirstName"
-
Nov 21st, 2007, 11:49 AM
#5
Re: [RESOLVED] Search and Sort Question
You do the same as you would for an If statement in VB - use AND or OR (or a combination of both), as appropriate.
So, if you want both conditions to be true, use And:
Code:
& " AND LastName Like'" & txt_Last.Text & "%'" _
..and if you want either of them (or both) to be true, use OR.
-
Nov 21st, 2007, 12:00 PM
#6
Thread Starter
Lively Member
Re: [RESOLVED] Search and Sort Question
I figured as much and had tried that.
I see now I had a typo.
Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|