Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 13th, 2004, 05:28 AM
smanna smanna is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: england
Posts: 18 smanna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
searching by keyword

Hi I havea form which interrogates this page."key" is a text box into which the user can write,"city and cat" are dropdown menus.The problem is that this code doesnt search for my keyword inserted by the user into "key". It just puts the whole content of the database onto the page.How do I change (title like '%"&key&"%' OR text like '%"&key&"%') so that it only gives back records containing the inserted keyword in the fields text or title? Thanks to anyone who can help

<% key=request.form("key")
city=request.form("city")
cat=request.form("cat")%
<%if cat ="none" then%>please select a category<%ELSE%>
<%sql="select * from users where title like '%"&key&"%' OR text like '%"&key&"%' AND city like '%"&city&"%' AND cat like '%"&cat&"%'"%>

Reply With Quote
  #2  
Old February 13th, 2004, 07:00 PM
davedenn davedenn is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 7 davedenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Text box problem

Hi!

I have a similar problem with a text box where all records are returned when the query on the data the user enters in the box is executed. I have attached my code below. Maybe if you have a chance you can look at mine an give me some pointers on how you use the syntax for limiting the search of the db to just the one record associated with that ID# (that's my field I need to search). Here's my code. it works well to merge the data into a Word document, except for the single merge problem.

Private Sub Text151_BeforeUpdate(Cancel As Integer)

Dim objWord As Word.Document
Set objWord = GetObject("C:\aden.doc", "Word.Document")
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\DoctorDB.mdb", _
LinkToSource:=True, _
Connection:="QUERY QryAdenCard", _
SQLStatement:="SELECT * FROM [QryAdenCard]"
strSQL = " SELECT QryAdenCard.ID#, FROM QryAdenCard WHERE (((QryAdenCard.ID#)= '" & strID# & "));"
objWord.MailMerge.Execute
objWord.Application.Documents(2).Close wdDoNotSaveChanges
DoCmd.Hourglass False
Set objWord = Nothing
Set objDoc = Nothing
End Sub




Quote:
Originally Posted by smanna
Hi avea form which interrogates this page."key" is a text box into which the user can write,"city and cat" are dropdown menus.The problem is that this code doesnt search for my keyword inserted by the user into "key". It just puts the whole content of the database onto the page.How do I change (title like '%"&key&"%' OR text like '%"&key&"%') so that it only gives back records containing the inserted keyword in the fields text or title? Thanks to anyone who can help

<% key=request.form("key")
city=request.form("city")
cat=request.form("cat")%
<%if cat ="none" then%>please select a category<%ELSE%>
<%sql="select * from users where title like '%"&key&"%' OR text like '%"&key&"%' AND city like '%"&city&"%' AND cat like '%"&cat&"%'"%>

Reply With Quote
  #3  
Old February 14th, 2004, 04:02 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
Not that sure about Asp but..

sql="select * from users where title like '%"&key&"%' OR text like '%"&key&"%' AND city like '%"&city&"%' AND cat like '%"&cat&"%'"

IS not the best way to write SQL

Assuming that the % is a wildcard charcter used with ASp (like SQL Server) that means "can be anything" (Access uses *).

You should use a statement like
sql="select * from users where title like '"&key&"' OR text like '"&key&"' AND city like '"&city&"' AND cat like '"&cat&"'"

If you really want to use a wildcard include that as part of the variable when needed. By including them before and after(by default) you are telling the DB that I want every record where my keyword exists as part of that field.

For eaxmple if you have entered a A as criteria for the Title, you old SQl would bring back every record that had an "a" somewhere in the field. And since City and Cat as drop downs, the only time you wish to use a Wildcard is when they don't have one selected. If they selected on you don't want to use a wildcard.

Good Luck

S-

Reply With Quote
  #4  
Old February 15th, 2004, 02:40 PM
smanna smanna is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: england
Posts: 18 smanna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
reply

Thanks for your help.this stopped all the records being showed only now none of the records are shown even if the keyword exists.
Quote:
Originally Posted by sbaxter
Not that sure about Asp but..

sql="select * from users where title like '%"&key&"%' OR text like '%"&key&"%' AND city like '%"&city&"%' AND cat like '%"&cat&"%'"

IS not the best way to write SQL

Assuming that the % is a wildcard charcter used with ASp (like SQL Server) that means "can be anything" (Access uses *).

You should use a statement like
sql="select * from users where title like '"&key&"' OR text like '"&key&"' AND city like '"&city&"' AND cat like '"&cat&"'"

If you really want to use a wildcard include that as part of the variable when needed. By including them before and after(by default) you are telling the DB that I want every record where my keyword exists as part of that field.

For eaxmple if you have entered a A as criteria for the Title, you old SQl would bring back every record that had an "a" somewhere in the field. And since City and Cat as drop downs, the only time you wish to use a Wildcard is when they don't have one selected. If they selected on you don't want to use a wildcard.

Good Luck

S-

Reply With Quote
  #5  
Old February 16th, 2004, 12:30 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
Are you sure you are passing you wildcard character through in the variable

You enter a value in to key, you should also enter a * (or %) into both City and Cat.

i do this all the time and don't have any problems.

Good Luck

S-

Reply With Quote
  #6  
Old February 16th, 2004, 05:21 PM
smanna smanna is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: england
Posts: 18 smanna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Heres How The Page Is

the entire form page and form processing page look like this:

FORM.HTML
<form method="post" action="adsearchresult.asp" name="">
<input type="text" name="key" size="20">
<select name="city">
<option value="london">london</option>
<option value="cambridge">cambridge</option>
</select>
<input type="submit" name="submit" value="search">
<input type="reset" name="submit2" value="Reset">
</form>
---------------------------------------------
adsearchresult.asp

<%key=Request.querystring("key")%>
<%city=request.form("city")%>
<%sql="select * from users where title like '"&key&"' OR text like '"&key&"' AND city like '%"&city&"%'"%>
<%Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=e:\users\ads.mdb"
Set RS=OBJdbConnection.Execute(sql)%>
<%Do while NOT RS.EOF%>
<%rec=rec+1%>
<%response.write(RS("title"))
title=rs("title")%>
<%

RS.MoveNext
Loop
RS.Close
OBJdbConnection.Close%>


Quote:
Originally Posted by sbaxter
Are you sure you are passing you wildcard character through in the variable

You enter a value in to key, you should also enter a * (or %) into both City and Cat.

i do this all the time and don't have any problems.

Good Luck

S-

Reply With Quote
  #7  
Old February 16th, 2004, 06:15 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
Like I mentioned earlier i am not sure about the ASP....

So i don't know if I will be of any additional help to you. Post you question on the ASP part of the forum. Most everyone int eh Access part of the forum program in Access or VB only. Most ASP related questions go unanswered.

S-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > searching by keyword


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway