Avoid On Error Resume Next?

J

jason

Is there a way to avoid On Error Resume Next for:

cnn.Open strCon
SQL = "EXEC Customer @txtEmail='" & email_address & "'"
set rs = cnn.execute(SQL)

'On error resume next
rs("email_address")

'// This record does not exist thus throwing up an error. I could use On
Error to resume and then do this
'// If rs.eof or rs.bof
'//

.....But I hate this convention as I find debugging a problem. Is there a
better way?

Thanks
Jason
 
R

Ray at

cnn.Open strCon
SQL = "EXEC Customer @txtEmail='" & email_address & "'"
set rs = cnn.execute(SQL)

If rs.EOF Then
'''empty
Else
sEmailAddress = rs.fields.item(0).value
End If


I believe that should work just fine. What part don't you like, the
checking for eof? Will this ever be true anyway? That would depend on your
stored procedure. Like, you could make it so that there is always a result
returned.

Ray at work
 
K

Kris Eiben

You don't like "if rs.EOF"? That's the standard way to deal with
possibly empty recordsets. What about it causes debugging problems for
you? What information do you need that you're not getting from
something like:

set rs = cnn.execute(SQL)
response.write "Executed SQL: " & SQL & "<br>"
if rs.EOF then
response.write "Sorry, no email address found."
else
response.write "Found email address " & rs("email_address")
end if
 
J

jason

But, the problem is that when there is no record matching the emial I pick
up an .EOF or BOF errror, thus I cannot I do a If rs.eof to trap the error
unless I use On Error Resume Next:

set cnn = Server.CreateObject("ADODB.Connection")
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("../database/listings.mdb") '//This one is for Access
2000/2002

cnn.Open strCon
SQL = "EXEC Customer @txtEmail='" & email_address & "'"
set rs = cnn.execute(SQL)

'On error resume next
email_address=rs("email_address") '//*** ERROR OCCURS AT THIS POINT, BUT IT
WILL NOT ALLOW
'// ME TO GO TO THE Recordset eof or bof stage UNLESS I place On Error
Resume Next before the variable assignment.

If rs.eof or rs.bof then

etc

End If

I must be missing something here. My query is programmed to accept NULL
values (=ALL RECORDS) or a specific email address for the paramater.

What am I doing wrong here.

- Jason
 
R

Ray at

This is why you check for rs.EOF BEFORE you try to call a value from the RS,
as I did in the code I provided.

Ray at work
 
J

jason

Sorry Ray - how stupid of me! I was trying to extract the email knowing it
did not exist - thus making my .EOF check invalid. Sorry for wasting your
time!
- Jason
 
J

jason

Thanks Ken - I was stupidly trying to pull an email that did not exist thus
making the .EOF check invalid

Cheers
Jason
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top