Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2006
    Thanked 0 Times in 0 Posts

    Entire recordset appears on page load?!

    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!

  2. #2
    Registered User
    Join Date
    Jan 2006
    Thanked 0 Times in 0 Posts
    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts