View Full Version : Entire recordset appears on page load?!

03-24-2006, 04:25 PM
I have been tasked with creating a search/results page, and really have little to no idea what I am doing. I recieved help from a local tech guy, but have not been able to get a hold of him to solve this problem with the code that he sent me.

<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source= C:\Inetpub\NewHermantown\StaffDirectory\db1.mdb"

<form name="form1" method="post" action="directory.asp">
Enter part or all of the employee's last name:<br>
<input type="text" name="srch_last">
<input type="submit" name="Submit" value="Search">
<div align="left">
strSQL = "SELECT LastName, FirstName, EmailName FROM Employees " & _
"WHERE LastName ALIKE """ & Request.Form("srch_last") & "%"" ORDER BY LastName, FirstName, EmailName;"

Set rsItems = Server.CreateObject("ADODB.Recordset")
rsItems.Open strSQL, objConn
If Not rsItems.EOF Then
Do While Not rsItems.EOF
Response.Write rsItems("LastName") & ", " & rsItems("FirstName") & ", " & rsItems("EmailName") & ", " & "<br>"
Set rsItems = Nothing
Response.Write "<CENTER><H2>No employees match your search.</H2></CENTER>"
End If

When the page loads, the entire recordset is sitting there where the results should be. What line of code am I missing to tell it NOT to display anything when the page loads?

Any help is greatly appreciated!

03-24-2006, 07:15 PM
Yes, I assume it does because you're not running a check to make sure someone has hit the submit button. Wrap your entire <div> for displaying the results in an if statement.

If Request.Form("srch_last") <> "" Then
blah blah
End If