David Ehmer wrote:
The code below is 2 rows in a table, the top row contains a message
to be shown if the recordset returns no matches. The 2nd row will
display any matches.
Problem is that if no matches are found nothing is displayed in this
table. I have used the code that DMX generates using the server
behaviour 'Show region if recordset is empty', but no success.
Appreciate someone pointing out where I'm going wrong here.
Thanks
David
I am assuming you have a scrollable cursor, and that some recordset
navigation has taken place before this block of code, explaining the need to
test both EOF and BOF.
<% If rsOrg.EOF Or rsOrg.BOF Then >
The "Or" should be "And" here. Your recordset contains no records only if
BOTH EOF and BOF are true, so you need to use "And". If some previous code
in this page had looped through the recordset so that it was at EOF, then
you would get the "no records" message when there actually were records.
Sorry, no records were found to match your search.
<% End If ' end rsOrg.EOF And rsOrg.BOF %</td>
</tr>
<tr>
<td>
<% If Not rsOrg.EOF Or Not rsOrg.BOF Then %>
This If statement will allow the following line of code to run if either EOF
or BOF is true, which will raise an error.
With that in mind, let's analyze this statement:
Assume that the previous code had looped through the recordset until the
recordset was at EOF (EOF = true). The first boolean expression, Not
rsOrg.EOF, will evaluate to False. So far so good.
However, the second expression, Not rsOrg.BOF, will evaluate to True! Not
good, because the Or operator has been used, causing the entire espression
to evaluate to True (Or causes the expression to be True if at least one of
the sub-expressions is True). So the following statement will be executed,
and an error will be raised when the field values are attempted to be read.
A better way to write to write this statement would be
If Not (rsOrg.EOF Or rsOrg.BOF) Then
Now if either EOF or BOF is true, the expression in the parentheses will
evaluate to True. The Not will change the result to False, and the following
code will not run. Conversely, if neither EOF and BOF is true, then the
parenthetical expression will evaluate to False, and the Not will change it
to True, allowing the following code to run.
However, I do not believe we have found your problem yet. How are you
verifying that the recordset actually contains records?
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"