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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a search function to query MS-Access database

Status
Not open for further replies.

jcpelejo

Programmer
Jul 29, 2001
70
US
Hello,

I was wondering if someone could help me create a search function for my ASP page where it searches for specific information from fields RecordID, DateReceived, AgreementNumber, ReviewDate, Processor or DateReturned from the TRANSFER table in the TRANSFER database. I would like the search to pop up only relevant information in the listing. The code that I have so far is the following:

<!-- #include file=utils.inc -->
<html>
<head>
<!-- #include file =&quot;fontCss.inc&quot; -->
<title>Online Transfer Form</title>
</head>
<body>
<center><table width=75%>





<tr><td> <b>Records in TRANSFER</b><br></td></tr>

<% 'check if we need to display a message(if a record has been inserted,updated or deleted

select case request.querystring(&quot;s&quot;)

case &quot;1&quot;%>

<tr><td><font color=red size=1>Record added!</font></td></tr>

<%case &quot;2&quot;%>

<tr><td><font color=red size=1>Changes saved!</font></td></tr>

<%case &quot;3&quot;%>

<tr><td><font color=red size=1>Record removed!</font></td></tr>

<%end select%>

<tr><td><font color=red>+</font><a href=TRANSFERaddform.asp>Add record</a><br><br></td></tr>
<%'get the records!

strsql=&quot;select * from [TRANSFER]&quot;

rs.open strsql,mydsn

'check for records!

if rs.eof and rs.bof then %>

<tr><td>No records!</td></tr>

<%else

'find what page we're on

If request.querystring(&quot;page&quot;) = &quot;&quot; Then

pageno = 1

Else

pageno = request.querystring(&quot;page&quot;)

End If

rs.pagesize = 20

totalpages = CInt(rs.pagecount)

'sets recordsets current page

rs.absolutepage = pageno

If totalpages > 1 Then

'forward/next buttons

response.write&quot;<tr><td>&quot;

If pageno > 1 Then

response.write &quot;<A href=TRANSFERlistAdmin.asp?page=&quot; & pageno - 1 & &quot;>previous</a> &quot;

End If

If int(pageno) < int(totalpages) Then

response.write &quot;<A href=TRANSFERlistAdmin.asp?page=&quot; & pageno + 1 & &quot;>next</a> &quot;

End If

response.write(&quot;<BR>&quot;)

'write the page numbers

For A = 1 To totalpages

If Int(A) = Int(pageno) Then

Response.write &quot;<font color=red>&quot; & A & &quot;</font> &quot;

Else

Response.write &quot;<A href=TRANSFERlistadmin.asp?page=&quot; & A & &quot;>&quot; & A & &quot;</font></a> &quot;

End If

Next

response.write&quot;</td></tr>&quot;

End If %>
</table>
<table width=&quot;75%&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; border=&quot;0&quot;>
<tr bgcolor=#CCCCCC>
<td width=16% ><b>Record ID</b></td>
<td width=16% ><b>Date Received</b></td>
<td width=16% ><b>Agreement Number</b></td>
<td width=16% ><b>Review Date</b></td>
<td width=16% ><b>Processor</b></td>
<td width=16% ><b>Resubmission Received Date</b></td>
</tr>

<%x=0

'now display the records

bg=0

For x = 1 To 20

bg=bg+1

If rs.EOF Then

'we're at the end of the recordset so exit..

Exit For

Else

'do alternating row colors

doBg= bg mod 2

if dobg=0 then

strBg=&quot;#F7F7F7&quot;

Else

strBg=&quot;#FFFFFF&quot;

End if

'write the link to the detail screen %>

<tr bgcolor=&quot;<%=strbg%>&quot;>

<td width=16% ><a href=TRANSFERdetailAdmin.asp?id=<%=rs(&quot;RecordID&quot;)%>&pageno=<%=pageno%>><%=rs(&quot;RecordID&quot;)%></a></td>

<td width=16% ><a href=TRANSFERdetailAdmin.asp?id=<%=rs(&quot;RecordID&quot;)%>&pageno=<%=pageno%>><%=rs(&quot;DateReceived&quot;)%></a></td>

<td width=16% ><a href=TRANSFERdetailAdmin.asp?id=<%=rs(&quot;RecordID&quot;)%>&pageno=<%=pageno%>><%=rs(&quot;AgreementNumber&quot;)%></a></td>

<td width=16% ><a href=TRANSFERdetailAdmin.asp?id=<%=rs(&quot;RecordID&quot;)%>&pageno=<%=pageno%>><%=rs(&quot;ReviewDate&quot;)%></a></td>

<td width=16% ><a href=TRANSFERdetailAdmin.asp?id=<%=rs(&quot;RecordID&quot;)%>&pageno=<%=pageno%>><%=rs(&quot;Processor&quot;)%></a></td>

<td width=16% ><a href=TRANSFERdetailAdmin.asp?id=<%=rs(&quot;RecordID&quot;)%>&pageno=<%=pageno%>><%=rs(&quot;DateReturned&quot;)%></a></td>

</tr>

<%end if

rs.movenext

next

end if%>

<%'clean up!

rs.close

set rs=nothing%>
</table></center></body></html>

Please advise. Thank you.



Life is too short to waste...
Julius Pelejo
jcpelejo@hotmail.com
 
dont know if you know how an MS SQL statement is designed but to query for certain results you'll need to add conditions to the statement you have :


strsql=&quot;select * from [TRANSFER]&quot;

you have the fields RecordID, DateReceived, AgreementNumber, ReviewDate, Processor or DateReturned to search in , and they appear by name to be different datatypes which will require some handling for the data types, as in text needs to be in single quotes and numeric data ouside of quotes and dates in # signs


but add onto it from your source of user input :

strsql=&quot;select * from [TRANSFER] Where DateReceived ...

this is where you need to specify = , >= , or <= and
then put in the value you're comparing against ( from user input ) concatenate the additional search values with OR or AND depending on what logics you want in order to create the recordset you need.

i would highly suggest looking into the faq's in regards to adding user input to a form (if that's not already in one of the includes ) and SQL statement help in regards to putting the proper search query together.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top