Avoid On Error Resume Next?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jason

    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_addre ss")

    '// 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

    #2
    Re: Avoid On Error Resume Next?

    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" <jason@catamara nco.com> wrote in message
    news:uOUw0GqYDH A.652@TK2MSFTNG P10.phx.gbl...[color=blue]
    > 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_addre ss")
    >
    > '// 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
    >
    >[/color]


    Comment

    • Kris Eiben

      #3
      Re: Avoid On Error Resume Next?

      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_addre ss")
      end if

      "jason" <jason@catamara nco.com> wrote in message
      news:uOUw0GqYDH A.652@TK2MSFTNG P10.phx.gbl...[color=blue]
      > 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_addre ss")
      > '// This record does not exist thus throwing up an error. I could use[/color]
      On[color=blue]
      > 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[/color]
      there a[color=blue]
      > better way?
      > Thanks
      > Jason[/color]


      Comment

      • jason

        #4
        Re: Avoid On Error Resume Next?

        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.CreateOb ject("ADODB.Con nection")
        strCon = "Provider=Micro soft.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=r s("email_addres s") '//*** 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:O8NiPNqYDH A.4020@tk2msftn gp13.phx.gbl...[color=blue]
        > 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[/color]
        your[color=blue]
        > stored procedure. Like, you could make it so that there is always a[/color]
        result[color=blue]
        > returned.
        >
        > Ray at work
        >
        > "jason" <jason@catamara nco.com> wrote in message
        > news:uOUw0GqYDH A.652@TK2MSFTNG P10.phx.gbl...[color=green]
        > > 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_addre ss")
        > >
        > > '// 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[/color][/color]
        a[color=blue][color=green]
        > > better way?
        > >
        > > Thanks
        > > Jason
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Ray at

          #5
          Re: Avoid On Error Resume Next?

          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" <jason@catamara nco.com> wrote in message
          news:OwevXbqYDH A.2236@TK2MSFTN GP10.phx.gbl...[color=blue]
          > 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.CreateOb ject("ADODB.Con nection")
          > strCon = "Provider=Micro soft.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=r s("email_addres s") '//*** ERROR OCCURS AT THIS POINT, BUT[/color]
          IT[color=blue]
          > 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:O8NiPNqYDH A.4020@tk2msftn gp13.phx.gbl...[color=green]
          > > 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[/color]
          > your[color=green]
          > > stored procedure. Like, you could make it so that there is always a[/color]
          > result[color=green]
          > > returned.
          > >
          > > Ray at work
          > >
          > > "jason" <jason@catamara nco.com> wrote in message
          > > news:uOUw0GqYDH A.652@TK2MSFTNG P10.phx.gbl...[color=darkred]
          > > > 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_addre ss")
          > > >
          > > > '// This record does not exist thus throwing up an error. I could use[/color][/color][/color]
          On[color=blue][color=green][color=darkred]
          > > > 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[/color][/color][/color]
          there[color=blue]
          > a[color=green][color=darkred]
          > > > better way?
          > > >
          > > > Thanks
          > > > Jason
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • jason

            #6
            Re: Avoid On Error Resume Next?

            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:OQDjEeqYDH A.2204@TK2MSFTN GP12.phx.gbl...[color=blue]
            > This is why you check for rs.EOF BEFORE you try to call a value from the[/color]
            RS,[color=blue]
            > as I did in the code I provided.
            >
            > Ray at work
            >
            > "jason" <jason@catamara nco.com> wrote in message
            > news:OwevXbqYDH A.2236@TK2MSFTN GP10.phx.gbl...[color=green]
            > > But, the problem is that when there is no record matching the emial I[/color][/color]
            pick[color=blue][color=green]
            > > up an .EOF or BOF errror, thus I cannot I do a If rs.eof to trap the[/color][/color]
            error[color=blue][color=green]
            > > unless I use On Error Resume Next:
            > >
            > > set cnn = Server.CreateOb ject("ADODB.Con nection")
            > > strCon = "Provider=Micro soft.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=r s("email_addres s") '//*** ERROR OCCURS AT THIS POINT, BUT[/color]
            > IT[color=green]
            > > 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:O8NiPNqYDH A.4020@tk2msftn gp13.phx.gbl...[color=darkred]
            > > > 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[/color][/color][/color]
            on[color=blue][color=green]
            > > your[color=darkred]
            > > > stored procedure. Like, you could make it so that there is always a[/color]
            > > result[color=darkred]
            > > > returned.
            > > >
            > > > Ray at work
            > > >
            > > > "jason" <jason@catamara nco.com> wrote in message
            > > > news:uOUw0GqYDH A.652@TK2MSFTNG P10.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_addre ss")
            > > > >
            > > > > '// This record does not exist thus throwing up an error. I could[/color][/color][/color]
            use[color=blue]
            > On[color=green][color=darkred]
            > > > > 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[/color][/color]
            > there[color=green]
            > > a[color=darkred]
            > > > > better way?
            > > > >
            > > > > Thanks
            > > > > Jason
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • jason

              #7
              Re: Avoid On Error Resume Next?

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

              Cheers
              Jason
              "Kris Eiben" <eibenkthisisfo rspammers@yahoo .com> wrote in message
              news:ObmkwRqYDH A.2548@TK2MSFTN GP09.phx.gbl...[color=blue]
              > 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_addre ss")
              > end if
              >
              > "jason" <jason@catamara nco.com> wrote in message
              > news:uOUw0GqYDH A.652@TK2MSFTNG P10.phx.gbl...[color=green]
              > > 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_addre ss")
              > > '// This record does not exist thus throwing up an error. I could use[/color]
              > On[color=green]
              > > 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[/color]
              > there a[color=green]
              > > better way?
              > > Thanks
              > > Jason[/color]
              >
              >[/color]


              Comment

              • Ray at

                #8
                Re: Avoid On Error Resume Next?

                No waste at all!

                Ray at home

                --
                Will trade ASP help for SQL Server help


                "jason" <jason@catamara nco.com> wrote in message
                news:OnvdgjqYDH A.2648@TK2MSFTN GP09.phx.gbl...[color=blue]
                > Sorry Ray - how stupid of me! I was trying to extract the email knowing[/color]
                it[color=blue]
                > did not exist - thus making my .EOF check invalid. Sorry for wasting your
                > time!
                > - Jason[/color]


                Comment

                Working...