how to avoid either eof or bof error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandru8
    New Member
    • Sep 2007
    • 145

    how to avoid either eof or bof error

    ho to all
    iam retrieving data from the access table when there is no data it saying either EOF or BoF true . how to avoid this.
    If IsNull(rs.Field s(0)) = True Then

    B = 1
    Else
    B = rs.Fields(0) + 1
    End If

    if there is no data b = 1 otherwise i need to increment that value B by 1
    thanks to all
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    You could try checking .RecordCount first, before using the fields.

    Comment

    • chandru8
      New Member
      • Sep 2007
      • 145

      #3
      I Tried Record Count For Many Times But It Doesn't Work For Me .
      Rs.recordcount Says -1
      Is It Correct

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        That means your query is not fetching anything.

        Comment

        • chandru8
          New Member
          • Sep 2007
          • 145

          #5
          data present in the table also recordcount says -1 only and

          for this condition

          if isnull(rs.field s(0)) = false then

          for the above condition if the table contain data or not it returns only false .

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            Try to execute your query in the backend and check if that returns any record or not .

            Comment

            • VBWheaties
              New Member
              • Feb 2008
              • 145

              #7
              The reason recordcount is -1 is because it has not traversed the set of records in the recordset. In other words, it doesn't know yet, how many records are in the recordset.

              To get the record count:

              Code:
               rs.Movelast
               rs.Movefirst
               Msgbox "There are " rs.RecordCount  & " records"
              However, this will be ineffective if there is no data.
              The best way to check for no data is to check both BOF and EOF as they will be true if no data exists.

              Code:
              If ((rs.EOF) And (rs.BOF)) Then
                 Msgbox "no data"
              End If

              Comment

              • dgzo
                New Member
                • Feb 2008
                • 2

                #8
                Trying
                Code:
                if not rs.eof then
                '...
                else
                '...
                end if
                could work also. So if your query does not return any records, the program does not execute what is inside the if part. And would not show any error.

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by VBWheaties
                  The reason recordcount is -1 is because it has not traversed ...
                  I just wanted to clarify this a bit, in case chandru8 didn't quite get it. When you first execute the query, the record count will be set to either 0 (no data) or 1 (some data). So you can use it as an indicator of whether something was found, but won't know the actual number of records until you go to the end of the recordset.

                  Very annoying, but it has been that way for a long time.

                  Comment

                  • chandru8
                    New Member
                    • Sep 2007
                    • 145

                    #10
                    thanks to all for your reply
                    Hi Killer
                    I tried this one and i fixed the problem by creating a new table . i dont know for that particular table its not working
                    from the begining the record count is not working for me can you give me some example for that
                    instead of rs.recordcount i used select count(field name)

                    thanks.

                    Comment

                    • Neelesh2007
                      New Member
                      • Oct 2007
                      • 41

                      #11
                      I think there is no need for moving Records to get Record count. Refresh the recordset & then use RecordCount. I think it will work.
                      e.g.
                      rs.refresh
                      if rs.recordcount= 0 then
                      .
                      .
                      Else
                      .
                      .
                      Endif

                      Comment

                      • Killer42
                        Recognized Expert Expert
                        • Oct 2006
                        • 8429

                        #12
                        Checking EOF and BOF is probably the better option, anyway.

                        I don't have any examples handy for recordcount, and don't actually do a lot of work with it. I just remember the problems with the records not being being until they're accessed.

                        Comment

                        Working...