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

Empty Recordset

Status
Not open for further replies.

kaycee79

Technical User
Jan 10, 2004
82
GB
Hi
On the page below, it produces a list of events which took place before the current date.
If there are no events, i want it to produce a message that says 'There are no Events to report on'
because currently it brings up an error message;

Error Type:
ADODB.Recordset (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/new/AddReport.asp, line 55

Can anyone help?

Thanks in advance

Code:
<%
Option Explicit
Dim StrConnect
%>

<!-- #INCLUDE FILE=&quot;ProjectConnection.asp&quot; -->

<%
	If Session(&quot;Username&quot;) = &quot;&quot; Then
		Response.Redirect &quot;Error.asp&quot;
	End If
%>

<HTML>
<HEAD>
<TITLE>Add Event Report</TITLE>
</HEAD>
<BODY>
<BODY bgcolor=&quot;#99CCFF&quot;>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<p align=&quot;center&quot;><u><b><font size=&quot;7&quot; face=&quot;Arial&quot;>Add an Event Report </font></b></u></p>

<table align=&quot;center&quot; cellspacing=&quot;5&quot; border=&quot;6&quot;>
<tr>
<td><font face=&quot;Arial&quot;><a href=&quot;RegisteredUsersHome.asp&quot;>Home</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;DiscussionBoard.asp&quot;>Discussion</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Feedback.asp&quot;>Feedback</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Donations.asp&quot;>Donation</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;NewsLetter.asp&quot;>Newsletter</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;SiteMap.asp&quot;>Site Map</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;AboutUs.asp&quot;>About Us</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Links.asp&quot;>Other Links</a></font></td>
</table>

<p align=&quot;center&quot;>
<font face=&quot;Arial&quot;>
<a href=&quot;EventReport.asp&quot;>Event Report</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;Events.asp&quot;>Forthcoming Events</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;PastEvents.asp&quot;>Past Events</a>
</font>
</p>
<p>
<font face=&quot;Arial&quot;>
<BR>


<%
Dim objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3
objRS.MoveFirst
%>Event Name </font>
</p>
<FORM ACTION = &quot;addreporttodb.asp&quot; METHOD= &quot;post&quot;>

<font face=&quot;Arial&quot;>

<SELECT NAME=&quot;EventName&quot; SIZE=&quot;1&quot;>

<%
Do While NOT objRS.EOF
Response.Write &quot;<OPTION VALUE='&quot; & objRS(&quot;Event Name&quot;) & &quot;'>&quot;
Response.Write objRS(&quot;Event Name&quot;) & &quot;</OPTION>&quot;
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
%>
</SELECT> </font>




<P><font face=&quot;Arial&quot;>Date<input type=&quot;text&quot; name = &quot;txtDate&quot; size=&quot;20&quot;><BR>
Report<BR> 
<textarea name=&quot;txtReport&quot; col=&quot;200&quot;  rows=&quot;12&quot; wrap=&quot;virtual&quot; cols=&quot;40&quot;></textarea> <BR>
<BR>


<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;></font></form>
</div>
</body>
</html>
 
After this:
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3

you do a:
objRS.MoveFirst

but if the recordset is empty, this results in an error.

So you must first check for objRS.eof:

if not objRS.eof then
...





hth,
Foxbox
ttmug.gif
 
further to foxbox's reponse:

objRS.MoveFirst is not necessary as it is the default


<%
Dim objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3

If objRs.EOF Then
Response.Write(&quot;There are no Events to report on&quot;)
Else


%>Event Name </font>
</p>
<FORM ACTION = &quot;addreporttodb.asp&quot; METHOD= &quot;post&quot;>

<font face=&quot;Arial&quot;>

<SELECT NAME=&quot;EventName&quot; SIZE=&quot;1&quot;>

<%
Do While NOT objRS.EOF
Response.Write &quot;<OPTION VALUE='&quot; & objRS(&quot;Event Name&quot;) & &quot;'>&quot;
Response.Write objRS(&quot;Event Name&quot;) & &quot;</OPTION>&quot;
objRS.MoveNext
Loop

End If

objRS.Close
Set objRS = Nothing
%>
 
i done that, but i am not sure if i put it in the right places, because
i am still getting an error message

Error Type:
Microsoft VBScript compilation (0x800A03F9)
Expected 'Then'
/new/AddReport.asp, line 57, column 16
If not objRS.EOF
---------------^

this is the how i did it

Code:
<%
Option Explicit
Dim StrConnect
%>

<!-- #INCLUDE FILE=&quot;ProjectConnection.asp&quot; -->

<%
	If Session(&quot;Username&quot;) = &quot;&quot; Then
		Response.Redirect &quot;Error.asp&quot;
	End If
%>

<HTML>
<HEAD>
<TITLE>Add Event Report</TITLE>
</HEAD>
<BODY>
<BODY bgcolor=&quot;#99CCFF&quot;>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<p align=&quot;center&quot;><u><b><font size=&quot;7&quot; face=&quot;Arial&quot;>Add an Event Report </font></b></u></p>

<table align=&quot;center&quot; cellspacing=&quot;5&quot; border=&quot;6&quot;>
<tr>
<td><font face=&quot;Arial&quot;><a href=&quot;RegisteredUsersHome.asp&quot;>Home</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;DiscussionBoard.asp&quot;>Discussion</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Feedback.asp&quot;>Feedback</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Donations.asp&quot;>Donation</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;NewsLetter.asp&quot;>Newsletter</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;SiteMap.asp&quot;>Site Map</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;AboutUs.asp&quot;>About Us</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Links.asp&quot;>Other Links</a></font></td>
</table>

<p align=&quot;center&quot;>
<font face=&quot;Arial&quot;>
<a href=&quot;EventReport.asp&quot;>Event Report</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;Events.asp&quot;>Forthcoming Events</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;PastEvents.asp&quot;>Past Events</a>
</font>
</p>
<p>
<font face=&quot;Arial&quot;>
<BR>


<%
Dim objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3
objRS.EOF

If not objRS.EOF
Then 
Response.Write &quot;There are no Events to Report on&quot;
Else

objRS.MoveFirst
%>Event Name </font>
</p>
<FORM ACTION = &quot;addreporttodb.asp&quot; METHOD= &quot;post&quot;>

<font face=&quot;Arial&quot;>

<SELECT NAME=&quot;EventName&quot; SIZE=&quot;1&quot;>

<%
Do While NOT objRS.EOF
Response.Write &quot;<OPTION VALUE='&quot; & objRS(&quot;Event Name&quot;) & &quot;'>&quot;
Response.Write objRS(&quot;Event Name&quot;) & &quot;</OPTION>&quot;
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
%>
</SELECT> </font>




<P><font face=&quot;Arial&quot;>Date<input type=&quot;text&quot; name = &quot;txtDate&quot; size=&quot;20&quot;><BR>
Report<BR> 
<textarea name=&quot;txtReport&quot; col=&quot;200&quot;  rows=&quot;12&quot; wrap=&quot;virtual&quot; cols=&quot;40&quot;></textarea> <BR>
<BR>


<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;></font></form>
<%
End If
%>

</div>
</body>
</html>
 
If not objRS.EOF
Then
Response.Write &quot;There are no Events to Report on&quot;
Else

put then on same line:

If not objRS.EOF Then
Response.Write &quot;There are no Events to Report on&quot;
Else




hth,
Foxbox
ttmug.gif
 
thanks for that, it worked, but even if there are no reports to report on,
the 2 text boxes for the date and report field still appear, i do not want them
there if there is nothin to report on. how can i do this?
the text boxes should only appear if there are events to report on

Thanks in advance

Code:
<%
Option Explicit
Dim StrConnect
%>

<!-- #INCLUDE FILE=&quot;ProjectConnection.asp&quot; -->

<%
	If Session(&quot;Username&quot;) = &quot;&quot; Then
		Response.Redirect &quot;Error.asp&quot;
	End If
%>

<HTML>
<HEAD>
<TITLE>Add Event Report</TITLE>
</HEAD>
<BODY>
<BODY bgcolor=&quot;#99CCFF&quot;>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<p align=&quot;center&quot;><u><b><font size=&quot;7&quot; face=&quot;Arial&quot;>Add an Event Report </font></b></u></p>

<table align=&quot;center&quot; cellspacing=&quot;5&quot; border=&quot;6&quot;>
<tr>
<td><font face=&quot;Arial&quot;><a href=&quot;RegisteredUsersHome.asp&quot;>Home</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;DiscussionBoard.asp&quot;>Discussion</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Feedback.asp&quot;>Feedback</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Donations.asp&quot;>Donation</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;NewsLetter.asp&quot;>Newsletter</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;SiteMap.asp&quot;>Site Map</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;AboutUs.asp&quot;>About Us</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Links.asp&quot;>Other Links</a></font></td>
</table>

<p align=&quot;center&quot;>
<font face=&quot;Arial&quot;>
<a href=&quot;EventReport.asp&quot;>Event Report</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;Events.asp&quot;>Forthcoming Events</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;PastEvents.asp&quot;>Past Events</a>
</font>
</p>
<p>
<font face=&quot;Arial&quot;>
<BR>


<%
Dim objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3

If objRs.EOF Then
Response.Write(&quot;There are no Events to report on&quot;)
Else


%>Event Name </font>
</p>
<FORM ACTION = &quot;addreporttodb.asp&quot; METHOD= &quot;post&quot;>

<font face=&quot;Arial&quot;>

<SELECT NAME=&quot;EventName&quot; SIZE=&quot;1&quot;>

<%
Do While NOT objRS.EOF
Response.Write &quot;<OPTION VALUE='&quot; & objRS(&quot;Event Name&quot;) & &quot;'>&quot;
Response.Write objRS(&quot;Event Name&quot;) & &quot;</OPTION>&quot;
objRS.MoveNext
Loop

End If

objRS.Close
Set objRS = Nothing
%>
</SELECT> </font>




<P><font face=&quot;Arial&quot;>Date<input type=&quot;text&quot; name = &quot;txtDate&quot; size=&quot;20&quot;><BR>
Report<BR> 
<textarea name=&quot;txtReport&quot; col=&quot;200&quot;  rows=&quot;12&quot; wrap=&quot;virtual&quot; cols=&quot;40&quot;></textarea> <BR>
<BR>


<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;></font></form>


</div>
</body>
</html>
 
you could make it so:

if objRS.eof then
' layout of complete page when no records are in the recordset
else
' layout when something is found
end if


or you set a variable onze and use this to make your page look 'clever':

dim lEmpty
if objRS.eof then
lEmpty = true
else
lEmpty = false
end if


and in the rest of the program you do:

if not lEmpty then
' put something on screen
end if











hth,
Foxbox
ttmug.gif
 
I tried the above code, and i am getting an error message;

Error Type:
Microsoft VBScript compilation (0x800A0400)
Expected statement
/new/test.asp, line 51
Event Name </font>

I am new to ASP, so i am not sure how to do many things just yet

this is the code;

Code:
<!-- #INCLUDE FILE=&quot;ProjectConnection.asp&quot; -->



<HTML>
<HEAD>
<TITLE>Add Event Report</TITLE>
</HEAD>
<BODY>
<BODY bgcolor=&quot;#99CCFF&quot;>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<p align=&quot;center&quot;><u><b><font size=&quot;7&quot; face=&quot;Arial&quot;>Add an Event Report </font></b></u></p>

<table align=&quot;center&quot; cellspacing=&quot;5&quot; border=&quot;6&quot;>
<tr>
<td><font face=&quot;Arial&quot;><a href=&quot;RegisteredUsersHome.asp&quot;>Home</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;DiscussionBoard.asp&quot;>Discussion</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Feedback.asp&quot;>Feedback</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Donations.asp&quot;>Donation</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;NewsLetter.asp&quot;>Newsletter</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;SiteMap.asp&quot;>Site Map</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;AboutUs.asp&quot;>About Us</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Links.asp&quot;>Other Links</a></font></td>
</table>

<p align=&quot;center&quot;>
<font face=&quot;Arial&quot;>
<a href=&quot;EventReport.asp&quot;>Event Report</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;Events.asp&quot;>Forthcoming Events</a>
&nbsp;&nbsp;&nbsp;
<a href=&quot;PastEvents.asp&quot;>Past Events</a>
</font>
</p>
<p>
<font face=&quot;Arial&quot;>
<BR>

<%
Dim objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3

If objRs.EOF Then
Response.Write(&quot;There are no Events to report on&quot;)

else

Event Name </font>
</p>
<FORM ACTION = &quot;addreporttodb.asp&quot; METHOD= &quot;post&quot;>

<font face=&quot;Arial&quot;>

<SELECT NAME=&quot;EventName&quot; SIZE=&quot;1&quot;>

<%
Do While NOT objRS.EOF
Response.Write &quot;<OPTION VALUE='&quot; & objRS(&quot;Event Name&quot;) & &quot;'>&quot;
Response.Write objRS(&quot;Event Name&quot;) & &quot;</OPTION>&quot;
objRS.MoveNext
Loop

End If

objRS.Close
Set objRS = Nothing
%>
</SELECT> </font>




<P><font face=&quot;Arial&quot;>Date<input type=&quot;text&quot; name = &quot;txtDate&quot; size=&quot;20&quot;><BR>
Report<BR> 
<textarea name=&quot;txtReport&quot; col=&quot;200&quot;  rows=&quot;12&quot; wrap=&quot;virtual&quot; cols=&quot;40&quot;></textarea> <BR>
<BR>


<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;></font></form>

%>

</div>
</body>
</html>
 
You are switching to plain HTML within the script:

If objRs.EOF Then
Response.Write(&quot;There are no Events to report on&quot;)

else

Event Name </font>


so either continue in script:
response.write &quot;Event name</font>&quot;

or use %> to stop the script processor



hth,
Foxbox
ttmug.gif
 
i am really sorry, but i am not able to do this, it is possible to show me on my code please?
 
<HTML>
<HEAD>
<TITLE>Add Event Report</TITLE>
</HEAD>
<BODY>
<BODY bgcolor=&quot;#99CCFF&quot;>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<p align=&quot;center&quot;><u><b><font size=&quot;7&quot; face=&quot;Arial&quot;>Add an Event Report </font></b></u></p>

<table align=&quot;center&quot; cellspacing=&quot;5&quot; border=&quot;6&quot;>
<tr>
<td><font face=&quot;Arial&quot;><a href=&quot;RegisteredUsersHome.asp&quot;>Home</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;DiscussionBoard.asp&quot;>Discussion</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Feedback.asp&quot;>Feedback</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Donations.asp&quot;>Donation</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;NewsLetter.asp&quot;>Newsletter</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;SiteMap.asp&quot;>Site Map</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;AboutUs.asp&quot;>About Us</a></font></td>
<td><font face=&quot;Arial&quot;><a href=&quot;Links.asp&quot;>Other Links</a></font></td>
</table>

<p align=&quot;center&quot;>
<font face=&quot;Arial&quot;>
<a href=&quot;EventReport.asp&quot;>Event Report</a>

<a href=&quot;Events.asp&quot;>Forthcoming Events</a>

<a href=&quot;PastEvents.asp&quot;>Past Events</a>
</font>
</p>
<p>
<font face=&quot;Arial&quot;>
<BR>

<%
Dim objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3

If objRs.EOF Then
Response.Write(&quot;There are no Events to report on&quot;)

else

'dont forget to close asp tags!!
%>

Event Name </font>
</p>
<FORM ACTION = &quot;addreporttodb.asp&quot; METHOD= &quot;post&quot;>

<font face=&quot;Arial&quot;>

<SELECT NAME=&quot;EventName&quot; SIZE=&quot;1&quot;>

<%
Do While NOT objRS.EOF
Response.Write &quot;<OPTION VALUE='&quot; & objRS(&quot;Event Name&quot;) & &quot;'>&quot;
Response.Write objRS(&quot;Event Name&quot;) & &quot;</OPTION>&quot;
objRS.MoveNext
Loop

End If

objRS.Close
Set objRS = Nothing
%>
</SELECT> </font>




<P><font face=&quot;Arial&quot;>Date<input type=&quot;text&quot; name = &quot;txtDate&quot; size=&quot;20&quot;><BR>
Report<BR>
<textarea name=&quot;txtReport&quot; col=&quot;200&quot; rows=&quot;12&quot; wrap=&quot;virtual&quot; cols=&quot;40&quot;></textarea> <BR>
<BR>


<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;></font></form>

%>

</div>
</body>
</html>
 
i tried the above code, and i am getting this error message now

Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/new/test.asp, line 40

Line 40 is
objRS.Open &quot;SELECT * FROM Events WHERE [date] < Now()&quot;, strConnect, 3,3
 
strConnect is a variable without a value there.
i suppose you forget to include:


<!-- #INCLUDE FILE=&quot;ProjectConnection.asp&quot; -->

if strConnect is not defined in there... where?






hth,
Foxbox
ttmug.gif
 
thanks for that, i think i have sorted out the problem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top