Operation is not allowed when the object is closed.

Discussion in 'ASP General' started by isaac2004, Feb 22, 2006.

  1. isaac2004

    isaac2004 Guest

    hi i am trying to use the record count object to count the number of
    books in a database of mine. i get this error saying that i have closed
    the object and i dont think i closed it. here is my code

    <% dim strBrowse, strSearch, Count


    Count = objRS.RecordCount

    strBrowse = request.querystring("strBrowse")
    strSearch = request.querystring("strSearch")

    if strBrowse > "" then
    strSQL = "SELECT distinctrow tblCategories.strCategory,
    tblBookDescription.ISBN, tblBookDescription.strTitle,
    tblBookDescription.strDescription " & _
    "FROM tblBookDescription INNER JOIN tblCategories ON
    tblBookDescription.ISBN = tblCategories.ISBN " & _
    "Where (((tblCategories.strCategory) = '" & strBrowse &
    "')) " & _
    "ORDER BY tblBookDescription.strTitle "

    End If
    if strSearch > "" then
    strSQL= "SELECT distinctrow tblBookDescription.strTitle,
    tblBookDescription.strDescription, tblBookDescription.ISBN " & _
    "FROM tblAuthors INNER JOIN (tblBookDescription INNER JOIN
    tblAuthorsBooks ON tblBookDescription.ISBN = tblAuthorsBooks.ISBN) ON
    tblAuthors.AuthorID = tblAuthorsBooks.AuthorID "&_
    "WHERE ((tblAuthors.strLastName Like '%"&strSearch&"%') "& _
    "OR (tblAuthors.strFirstName Like '%"&strSearch&"%') "&_
    "OR (tblBookDescription.strTitle Like '%"&strSearch&"%') "&_
    "OR (tblBookDescription.strDescription Like '% "&strSearch&"
    %') "& _
    "OR (tblBookDescription.strPublisher Like '%"&strSearch&"%'))
    "&_
    "ORDER BY tblBookDescription.strTitle;"
    end if

    'response.write("strSQL = " & strSQL)

    Set objRS = Server.CreateObject("ADODB.Recordset")
    -----------------------------------------------------------------------------error
    here
    objRS.open strSQL, objConn, 1, objRS.RecordCount



    %>
    </td>
    <td valign="top"><font face="Comic Sans MS" color="blue">
    <%
    if strBrowse > "" and Count = 1 then
    response.write("We Carry " & Count & " " & strBrowse & "
    book.")
    else if strBrowse > "" and Count > 1 then
    response.write("We Carry " & Count & " " & strBrowse & "
    books.")
    end if
    end if

    if strSearch > "" and Count = 1 then
    response.write("Search results: " & Count & " book matches '"
    & strSearch & "'.")
    else if strSearch > "" and Count > 1 then
    response.write("Search results: " & Count & " books match '" &
    strSearch & "'.")
    end if
    end if


    %>


    thanks for the help
     
    isaac2004, Feb 22, 2006
    #1
    1. Advertising

  2. isaac2004

    dNagel Guest

    I believe the last parameter to Open should be a 3 for a dynamic recordset.

    objRS.open strSQL, objConn, 1, 3

    next, this line of code :

    Count = objRS.RecordCount

    is being called before the recordset is open, thus the RS is not OPEN yet...

    D.


    isaac2004 wrote:
    > hi i am trying to use the record count object to count the number of
    > books in a database of mine. i get this error saying that i have closed
    > the object and i dont think i closed it. here is my code
    >
    > <% dim strBrowse, strSearch, Count
    >
    >
    >
    >
    > strBrowse = request.querystring("strBrowse")
    > strSearch = request.querystring("strSearch")
    >
    > if strBrowse > "" then
    > strSQL = "SELECT distinctrow tblCategories.strCategory,
    > tblBookDescription.ISBN, tblBookDescription.strTitle,
    > tblBookDescription.strDescription " & _
    > "FROM tblBookDescription INNER JOIN tblCategories ON
    > tblBookDescription.ISBN = tblCategories.ISBN " & _
    > "Where (((tblCategories.strCategory) = '" & strBrowse &
    > "')) " & _
    > "ORDER BY tblBookDescription.strTitle "
    >
    > End If
    > if strSearch > "" then
    > strSQL= "SELECT distinctrow tblBookDescription.strTitle,
    > tblBookDescription.strDescription, tblBookDescription.ISBN " & _
    > "FROM tblAuthors INNER JOIN (tblBookDescription INNER JOIN
    > tblAuthorsBooks ON tblBookDescription.ISBN = tblAuthorsBooks.ISBN) ON
    > tblAuthors.AuthorID = tblAuthorsBooks.AuthorID "&_
    > "WHERE ((tblAuthors.strLastName Like '%"&strSearch&"%') "& _
    > "OR (tblAuthors.strFirstName Like '%"&strSearch&"%') "&_
    > "OR (tblBookDescription.strTitle Like '%"&strSearch&"%') "&_
    > "OR (tblBookDescription.strDescription Like '% "&strSearch&"
    > %') "& _
    > "OR (tblBookDescription.strPublisher Like '%"&strSearch&"%'))
    > "&_
    > "ORDER BY tblBookDescription.strTitle;"
    > end if
    >
    > 'response.write("strSQL = " & strSQL)
    >
    > Set objRS = Server.CreateObject("ADODB.Recordset")
    > -----------------------------------------------------------------------------error
    > here
    > objRS.open strSQL, objConn, 1, objRS.RecordCount
    >
    >
    >
    > %>
    > </td>
    > <td valign="top"><font face="Comic Sans MS" color="blue">
    > <%
    > if strBrowse > "" and Count = 1 then
    > response.write("We Carry " & Count & " " & strBrowse & "
    > book.")
    > else if strBrowse > "" and Count > 1 then
    > response.write("We Carry " & Count & " " & strBrowse & "
    > books.")
    > end if
    > end if
    >
    > if strSearch > "" and Count = 1 then
    > response.write("Search results: " & Count & " book matches '"
    > & strSearch & "'.")
    > else if strSearch > "" and Count > 1 then
    > response.write("Search results: " & Count & " books match '" &
    > strSearch & "'.")
    > end if
    > end if
    >
    >
    > %>
    >
    >
    > thanks for the help
    >
     
    dNagel, Feb 23, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    2,121
    Kevin Spencer
    Aug 10, 2005
  2. Matthew Louden
    Replies:
    6
    Views:
    251
    Ken Schaefer
    Sep 28, 2003
  3. cliverama
    Replies:
    1
    Views:
    135
    Aaron Bertrand [MVP]
    Nov 5, 2003
  4. Guest
    Replies:
    1
    Views:
    234
    Ray Costanzo [MVP]
    Dec 20, 2004
  5. TC
    Replies:
    1
    Views:
    146
    madhouse
    Jan 12, 2005
Loading...

Share This Page