Forum Moderators: open

Message Too Old, No Replies

Object testing

How to check if an object exsists

         

HeadBut

8:09 pm on Nov 3, 2004 (gmt 0)

10+ Year Member



Object required: ''

/XXX/XXXFind.asp, line 126

126: <%if DinningOutCuisine.BOF <> True AND DinningOutCuisine.EOF <> True then%>

What is wrong with this line... seems to work in other pages!

Thanks
M

defanjos

9:29 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you create a recordset called DinningOutCuisine?

john_k

10:03 pm on Nov 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In addition to defanjos' question, here is the answer to your question (in the subtitle) of how to check if an object exists:

<%
If Not (DinningOutCuisine Is Nothing) Then
' Object okay, do your stuff here
If Not (DinningOutCuisine.EOF And DinningOutCuisine.BOF) Then %>
<!-- Process DinningOutCuisine recordset -->
<% Else %>
<!-- Object not set, do error handling -->
<% End If %>

HeadBut

3:10 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



Sometimes the object is set and sometimes not.
This:
"If Not (DinningOutCuisine Is Nothing) Then"

Gives me the same object error?

Thanks
Again!

defanjos

3:21 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sometimes the object is set and sometimes not

If you are going to call that recordset anywhere on the page, you have to set it first - I don't think there is another way.

You have to have something like this:
Set DiningoutCuisine = Server.CreateObject("ADODB.Recordset")
before you can "use" DiningoutCuisine

john_k

7:23 pm on Nov 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sometimes the object is set and sometimes not.

What defanjos said is correct. Your DiningOutCuisine variable has never been initialized as an object reference. Examine your code to ensure that the recordset object is being created.

Also, you can initialize the recordset object to Nothing and that will avoid this particular issue.

Dim DiningOutCuisine
Set DiningOutCuisine = Nothing