473,289 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Avoid On Error Resume Next?

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
Jul 19 '05 #1
7 5147
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

"jason" <ja***@catamaranco.com> wrote in message
news:uO*************@TK2MSFTNGP10.phx.gbl...
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

Jul 19 '05 #2
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

"jason" <ja***@catamaranco.com> wrote in message
news:uO*************@TK2MSFTNGP10.phx.gbl...
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

Jul 19 '05 #3
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

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:O8**************@tk2msftngp13.phx.gbl...
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

"jason" <ja***@catamaranco.com> wrote in message
news:uO*************@TK2MSFTNGP10.phx.gbl...
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


Jul 19 '05 #4
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

"jason" <ja***@catamaranco.com> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
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

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:O8**************@tk2msftngp13.phx.gbl...
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

"jason" <ja***@catamaranco.com> wrote in message
news:uO*************@TK2MSFTNGP10.phx.gbl...
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



Jul 19 '05 #5
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

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
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

"jason" <ja***@catamaranco.com> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
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

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:O8**************@tk2msftngp13.phx.gbl...
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

"jason" <ja***@catamaranco.com> wrote in message
news:uO*************@TK2MSFTNGP10.phx.gbl...
> 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
>
>



Jul 19 '05 #6
Thanks Ken - I was stupidly trying to pull an email that did not exist thus
making the .EOF check invalid

Cheers
Jason
"Kris Eiben" <ei*********************@yahoo.com> wrote in message
news:Ob**************@TK2MSFTNGP09.phx.gbl...
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

"jason" <ja***@catamaranco.com> wrote in message
news:uO*************@TK2MSFTNGP10.phx.gbl...
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


Jul 19 '05 #7
No waste at all!

Ray at home

--
Will trade ASP help for SQL Server help
"jason" <ja***@catamaranco.com> wrote in message
news:On**************@TK2MSFTNGP09.phx.gbl...
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

Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: aaron | last post by:
On Winxp Pro I try to trap an error: On error resume next If (Err.Number <> 0) Then End sub End If but no matter what the case Err.Number = 0. When I was using visual basic 6.0 on a win2k...
3
by: Michael | last post by:
Hello again everyone, Hope you can help. I have a form with a lot of code going on in the background but I can't find the route cause of the following error message. Update or Cancel Update...
2
by: deko | last post by:
I want to turn error handling off, then back on in a sub routine that backs up a select set of documents. For some reason, I can't seem to get this to work - Private Sub BackupDocs() On Error...
13
by: Steve Jorgensen | last post by:
== On Error Resume next, and Err.Number == If you want to call one of your procedures from another procedure, and check for errors afterward, you mayimagine that you should write code something...
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
3
by: bob.needler | last post by:
I know On Error Resume Next is generally considered lazy. But can someone tell me why the resume next in Exit_Handler does not seem to work? It generates the typical unhandled runtime error...
4
by: Neo | last post by:
I found on error resume next doesn't work in for each... e.g. on error resume next for each x in y 'do stuff next if you have an error in for each loop, it falls in infinite loop... it...
11
by: Maxwell2006 | last post by:
Hi, I know that this is not a good practice, but I wonder do we have "on error resume next" in C#? Thanks,
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.