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

ASP-No records in recordset

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
US
I'm a major newbie with ASP and VB Script, and am hoping for some assistance with the following:

When I run a query on a MS Access Database, and there are no records returned in the recordset, I received an error page. How would I change this code to instead, display a message on the page "Address was not found in our database, click here to try again" and using the "click here" part as a hyperlink back to the first page. Here is my loop
the creates a table filled by the recordsets found (if any).

<form action=&quot;GetPlace.asp&quot; method=&quot;post&quot;>
<select name=&quot;AddrDown&quot;>
<% 'Loop through the recordset, creating a list item
for each.%>

<% do while not rstSearch.eof%>
<Option Value=&quot;<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>&quot;>
<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>
</Option>

<%rstSearch.movenext
loop%>

</select>
<input type=&quot;submit&quot; value=Submit>
</form>

Hopefully, I've given you enough info to go on, to help me out. Thanks!!!
 
Hi ...
you can use this code ...

<%
If Not(rstSearch.BOF And rstSearch.EOF) Then
do while not rstSearch.eof
%>
<Option Value=&quot;<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>&quot;>
<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>
</Option>

<%rstSearch.movenext
loop
Else
Response.Write &quot;No Record Found !!!&quot;
End If
%>
----
TNX.
E.T.
 
Actually, you can just check for rstSearch.EOF (Which stands for End Of File)

That way, when no records are returned you are automatically at EOF. So

If rstSearch.EOF then
Response.Write &quot;No Record Found&quot;
else
do while not rstSearch.eof
%>
<Option Value=&quot;<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>&quot;>
<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>
</Option>
<%
rstSearch.movenext
loop
end if
The money's gone, the brain is shot.....but the liquor we still got.
 
I've tried this:
<% 'Loop through the recordset to make each entry in the list.
If rstSearch.EOF then
Response.Write &quot;No Record Found&quot;
else
Do While Not rstSearch.EOF
%>
<tr BGCOLOR=&quot;#DEE0F4&quot;>
<td><font face=&quot;Arial,Helvetica&quot;><font size=-1><%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %></font></font></td>
<td><font face=&quot;Arial,Helvetica&quot;><font size=-1><b><%= rstSearch.Fields(&quot;PLACE&quot;).Value %></b>&nbsp;-&nbsp;Located at:&nbsp;&nbsp;<%= rstSearch.Fields(&quot;PREC_ADDR&quot;).Value %>.</font></font></td>
</tr>
<%

rstSearch.MoveNext
Loop
End If
%>
</table></center>

<%
' Close our recordset and connection and dispose of the objects
rstSearch.Close
Set rstSearch = Nothing
cnnSearch.Close
Set cnnSearch = Nothing
End If
%>

and get this error >>>>>
Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.


and I've tried this:
<% 'Loop through the recordset to make each entry in the list.

If Not(rstSearch.BOF And rstSearch.EOF) Then
do while not rstSearch.eof
%>
<Option Value=&quot;<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>&quot;>
<%= rstSearch.Fields(&quot;PRP_ADDR&quot;).Value %>
</Option>

<%rstSearch.movenext
loop
Else
Response.Write &quot;No Record Found !!!&quot;
End If
%>

and I get this error >>>>>>
Error Type:
Microsoft VBScript compilation (0x800A03F6)
Expected 'End'

Any ideas?
 
Hi ...
both codes are working properly ...
maybe in the first one you have used a field name which is not in your table ...
and in the second one maybe you have not have equal number of ends for the begins such as if or sub or ...
check your complete page code.
----
TNX.
E.T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top