Avoid On Error Resume Next?

Discussion in 'ASP General' started by jason, Aug 14, 2003.

  1. jason

    jason Guest

    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
     
    jason, Aug 14, 2003
    #1
    1. Advertising

  2. jason

    Ray at Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Ray at, Aug 14, 2003
    #2
    1. Advertising

  3. jason

    Kris Eiben Guest

    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" <> wrote in message
    news:...
    > 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
     
    Kris Eiben, Aug 14, 2003
    #3
  4. jason

    jason Guest

    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:...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    jason, Aug 14, 2003
    #4
  5. jason

    Ray at Guest

    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" <> wrote in message
    news:...
    > 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:...
    > > 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" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ray at, Aug 14, 2003
    #5
  6. jason

    jason Guest

    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:...
    > 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" <> wrote in message
    > news:...
    > > 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:...
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    jason, Aug 14, 2003
    #6
  7. jason

    jason Guest

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

    Cheers
    Jason
    "Kris Eiben" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    > > 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

    >
    >
     
    jason, Aug 14, 2003
    #7
  8. jason

    Ray at Guest

    No waste at all!

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "jason" <> wrote in message
    news:...
    > 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, Aug 14, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: QUERY: 'On Error Resume Next' scope rules

    Kevin Spencer, Jun 17, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    592
    Kevin Spencer
    Jun 17, 2006
  2. Deniz Bahar
    Replies:
    2
    Views:
    492
    Andrey Tarasevich
    Mar 9, 2005
  3. Jitu>>

    On Error Resume Next

    Jitu>>, Jul 14, 2003, in forum: ASP General
    Replies:
    1
    Views:
    193
    Ray at
    Jul 14, 2003
  4. Laphan

    The truth re On Error Resume Next

    Laphan, Oct 26, 2005, in forum: ASP General
    Replies:
    3
    Views:
    128
    Bob Barrows [MVP]
    Oct 26, 2005
  5. jay
    Replies:
    1
    Views:
    130
    Austin Ziegler
    Feb 22, 2007
Loading...

Share This Page