-
1
- #1
Another ASP into UD code snippet I've used. Sometimes it's useful to offer a way to filter the search for users, especially if you're dealing with a large and complex recordset, eg this was used to search for members of a chamber of commerce that were listed within the database by all the usual fields (company name, town etc) and were also classified by the type of business.
I came up with a way to allow both a category (type) dropdown list to be used with or without a text field. For example you may want to search for all computer service companies but only deal with those offering network support. The text field was matched against the company activity (a 100 word description in the database). So you could search for 'computer services' with 'network' in the textfield or search all 'computer services' by leaving the text field ("keyword"
empty.
ENough of this, where's the code?
Dim SqlVar
SqlVar = "SELECT * FROM qryBusCategory"
If Request.QueryString("keyword"
= "CompanyDescription" Then
SqlVar = SqlVar & " WHERE BusCategory LIKE '%" & _
Request.QueryString("Type"
& "%'" & " WHERE CompanyDescription LIKE '%" & _
Request.QueryString("keyword"
& "%'"
Else
If Request.QueryString("keyword"
= "" Then
SqlVar = SqlVar & " WHERE BusCategory LIKE '%" & _
Request.QueryString("Type"
& "%'"
Else
If Request.QueryString("Type"
<> "BusCategory" Then
SqlVar = SqlVar & " WHERE CompanyDescription LIKE '%" & _
Request.QueryString("keyword"
& "%'"
End If
End If
End If
Again, this is basic ASP but with some tinkering it can work well within the framework of a UD project.
Any probs, post away.
Have fun.
M
I came up with a way to allow both a category (type) dropdown list to be used with or without a text field. For example you may want to search for all computer service companies but only deal with those offering network support. The text field was matched against the company activity (a 100 word description in the database). So you could search for 'computer services' with 'network' in the textfield or search all 'computer services' by leaving the text field ("keyword"

ENough of this, where's the code?
Dim SqlVar
SqlVar = "SELECT * FROM qryBusCategory"
If Request.QueryString("keyword"

SqlVar = SqlVar & " WHERE BusCategory LIKE '%" & _
Request.QueryString("Type"

Request.QueryString("keyword"

Else
If Request.QueryString("keyword"

SqlVar = SqlVar & " WHERE BusCategory LIKE '%" & _
Request.QueryString("Type"

Else
If Request.QueryString("Type"

SqlVar = SqlVar & " WHERE CompanyDescription LIKE '%" & _
Request.QueryString("keyword"

End If
End If
End If
Again, this is basic ASP but with some tinkering it can work well within the framework of a UD project.
Any probs, post away.
Have fun.
M