Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Search?

Status
Not open for further replies.

ade77

Technical User
Jul 17, 2000
4
0
0
GB
I am trying to search an Access database, using data entered from a form. The form offers users a choice of different text fields in which they can search the database with. It would be great if they could enter data in a number of the text fields to broaden the search, if this is possible? Could anyone please suggest how I can get the code below to do this, or if a multiple field search is not possible, then a single field search, but where the user still has a choice of which field to search by. I would be most appreciative of any help.<br><br><br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Brigantia Directory Search Results&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body bgcolor=&quot;#FFFFFF&quot;&gt;<br>&lt;b&gt;&lt;i&gt;&lt;font color=&quot;#000099&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;4&quot;&gt;Brigantia <br>Directory Search Results&lt;/font&gt;&lt;/i&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;<br>&lt;hr&gt;<br><br>&lt;% <br>&nbsp;Business= request.form(&quot;company&quot;)<br>&nbsp;Postcode= request.form(&quot;postcode&quot;)<br>&nbsp;Stdcode= request.form(&quot;stdcode&quot;)<br>&nbsp;Town= request.form(&quot;town&quot;)<br><br>&nbsp;set rs=server.createobject(&quot;adodb.recordset&quot;)<br><br><br>&nbsp;if Business = &quot;&quot; then<br>&nbsp;response.end<br>&nbsp;else<br>&nbsp;sql = &quot;select * from tablebrig &quot;<br>&nbsp;sql = sql& &quot; where lastname='&quot;&nbsp;&nbsp;& Business & &quot;';&quot;<br>&nbsp;end if<br>&nbsp;<br>&nbsp;<br>&nbsp;&nbsp;if postcode = &quot;&quot; then<br>&nbsp;response.end<br>&nbsp;else<br>&nbsp;sql = &quot;select * from tablebrig &quot;<br>&nbsp;sql = sql& &quot; where postcode='&quot;&nbsp;&nbsp;& Postcode & &quot;';&quot;<br>&nbsp;end if<br>&nbsp;<br><br><br>&nbsp;if Stdcode = &quot;&quot; then<br>&nbsp;response.end<br>&nbsp;else<br>&nbsp;sql = &quot;select * from tablebrig &quot;<br>&nbsp;sql = sql& &quot; where stdnumber='&quot;&nbsp;&nbsp;& Stdcode & &quot;';&quot;<br>&nbsp;end if<br>&nbsp;<br>&nbsp;<br>&nbsp;<br>&nbsp;if Town = &quot;&quot; then<br>&nbsp;response.end<br>&nbsp;else<br>&nbsp;sql = &quot;select * from tablebrig &quot;<br>&nbsp;sql = sql& &quot; where town='&quot;&nbsp;&nbsp;& Town & &quot;';&quot;<br>&nbsp;end if<br><br>&nbsp;<br>&nbsp;rs.open sql, &quot;DSN=brigantia&quot;<br>&nbsp;<br><br>&nbsp;rs.MoveFirst<br>&nbsp;response.write &quot;&lt;table border=1&gt;&quot;<br>&nbsp;Do while not rs.eof <br>&nbsp;response.write &quot;&lt;tr&gt;&lt;td&gt;&quot; & rs(&quot;lastname&quot;) & &quot;&lt;/td&gt;&quot;<br>&nbsp;response.write &quot;&lt;td&gt;&quot; & rs(&quot;postcode&quot;) & &quot;&lt;/td&gt;&quot;<br>&nbsp;response.write &quot;&lt;td&gt;&quot; & rs(&quot;stdnumber&quot;) & &quot;&lt;/td&gt;&quot;<br>&nbsp;response.write &quot;&lt;td&gt;&quot; & rs(&quot;city&quot;) & &quot;&lt;/td&gt;&lt;/tr&gt;&quot; <br>&nbsp;rs.movenext<br>&nbsp;loop<br>&nbsp;response.write &quot;&lt;/table&gt;&quot;<br>&nbsp;rs.close<br>&nbsp;set rs=nothing<br>&nbsp;<br>&nbsp;<br>%&gt;<br><br>&lt;hr&gt;<br><br>End of Page&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br>
 
use the AND keyword:<br><br>&quot;SELECT * FROM tablebrig WHERE lastname = '&quot; & Business & &quot;' AND postcode = &quot; & Postcode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top