Results 1 to 23 of 23

Thread: .eof or .bof is true, or current recordset has been deleted. requested operation requ

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    .eof or .bof is true, or current recordset has been deleted. requested operation requ

    when my table is empty i always encounter this error what will do.

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    That do you want the application to do?

    When I open a recordset before I do anything with it I check for .BOF and .EOF like this:

    VB Code:
    1. rs.Open strSQL
    2.   if Not rs.BOF and Not rs.EOF then
    3.      'Do something with the result set
    4.   else
    5.      'Something to do if nothing is there
    6.   end if
    7.   if not rs is Nothing then
    8.      if rs.State then rs.Close
    9.      set rs = Nothing
    10.   end if
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    i try your code but still have error... here's my code

    VB Code:
    1. Private Sub cmdSave_Click()
    2.  
    3. If CheckTextBox(txtDepTitle, "Invalid 'DEPARTMENT Title' value. This field is required, please enter a value.") = False Then
    4.          StartTxt txtDepTitle
    5. Else
    6.        With tbDepartment
    7.            .MoveFirst
    8.             .Find "DepartmentName = '" & txtDepTitle & "'"
    9.             If .EOF = True Then
    10.                 .AddNew
    11.                 .Fields(0) = txtDepTitle
    12.                 .Update
    13.                 .Requery
    14.              End If
    15.         End With
    16.    
    17.     ans = MsgBox("New Deparment entry successfully saved to the record." & vbNewLine & "Do You Want To Add Another Record?", vbYesNo, "Titus School Of Multimedia")
    18.     If ans = vbNo Then
    19.         Unload Me
    20.     End If
    21.    
    22. End If
    23.    
    24. End Sub

  4. #4
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation

    from ur code, try this one :

    Code:
    With tbDepartment '// Assumming this is an open recordset
               If .EOF or .BOF Then 
                   Msgbox "No Record(s)",64,App.Title
                  .Close
                  Exit Sub 
               End If 
               .MoveFirst
                .Find "DepartmentName = '" & txtDepTitle & "'"
                If .EOF = True Then
                End If
    End With

  5. #5
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    If there are no records then the .MoveFirst will cause the error. You need to test for BOF/EOF before you try and move in a recordset. Also when the recordset is first opened there is no need to issued the .MoveFirst method you are already at the first record.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    Quote Originally Posted by mheiy
    VB Code:
    1. Private Sub cmdSave_Click()
    2.  
    3. If CheckTextBox(txtDepTitle, "Invalid 'DEPARTMENT Title' value. This field is required, please enter a value.") = False Then
    4.          StartTxt txtDepTitle
    5. Else
    6.        With tbDepartment
    7.            .MoveFirst
    8.             .Find "DepartmentName = '" & txtDepTitle & "'"
    9.             If .EOF = True Then
    10.                 .AddNew
    11.                 .Fields(0) = txtDepTitle
    12.                 .Update
    13.                 .Requery
    14.              End If
    15.         End With
    16.    
    17.     ans = MsgBox("New Deparment entry successfully saved to the record." & vbNewLine & "Do You Want To Add Another Record?", vbYesNo, "Titus School Of Multimedia")
    18.     If ans = vbNo Then
    19.         Unload Me
    20.     End If
    21.    
    22. End If
    23.    
    24. End Sub
    Quote Originally Posted by mheiy
    when my table is empty i always encounter this error what will do.
    Why are you doing a .MoveFirst on an empty table? Why are you trying to Search an empty table?

    Either and both of those will result in an EOF error.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    what if there's a record already...

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    Quote Originally Posted by mheiy
    what if there's a record already...
    Then, if what you said in your first post
    Quote Originally Posted by mheiy
    when my table is empty i always encounter this error what will do.
    is true, you shouldn't get the error.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    ok at first my table is empty then im going to add new one... and add again other one

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    So, do you continue to get the .EOF/.BOF error when the table is not empty?

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    you dont understand me...
    what im trying to say is when my table is empty i got an error.. then you say that why do i need to .Movefirst and search... i need the .movefirst when my table is not empty.. got it

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation

    As mentioned several times, you can only do a MoveFirst or Find if there are records.. check EOF/BOF (as shown already - Just a noob's example is good) to see if there are records, and only do the .MoveFirst/Find if there are.

  13. #13
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation

    Code:
    Option Explicit
    
    Private c   As ADODB.Connection
    Private r   As ADODB.Recordset
    
    Private Function AddNewRec(IdentifyValue As String) As Boolean
    
    On Error Resume Next
        
        'No need for .MoveFirst or Looping throught recordset _
         if u just want to Add or Update record !!!
        
        With r
        
            .Open "select [Fields] from [Table] where [FieldIdentify]='" & _
                  IdentifyValue & "';", c, adOpenDynamic, adLockOptimistic
                  
            If (.EOF Or .BOF) Then .AddNew '/. No Record(s) that match _
                                               Criteria or table is Empty - AddNew
            .Fields(0).Value = "Some Value"
            .Update '/. if found match record from where clause _
                        perform - Update
            .Close
        End With
        
        AddNewRec = True
        
        If (Err <> 0) Then
           AddNewRec = False
           On Error GoTo 0
           Err.Clear
        End If
    
    End Function

  14. #14
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    Let's start with the code you use to open the record set. Can we see what you are doing? As alrready said if the recordset is empty and you do a .MoveFirst then you get an error. If the recordset is empty and you do a .Seach then you get an error. You can not perform either if the recordset is empty. So before you do either of them check for BOF/EOF. It either condition is true then you have and empty recordset and don't perform a .MoveFirst or .Search. just go to the add new if that is what you wnat to do.

    In trruth you should start to learn SQL language to reteive the data you wnat not just open a table and look for stuff in it.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    how can i know if there's an existing record already

  16. #16
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    When you open the recordset you perform this code (as I showed you in post number 2):

    VB Code:
    1. if Not tbDepartment.BOF and Not tbDepartment.EOF then
    2.       Do you stuff here
    3.   else
    4.       MsgBox "No Records returned NOTHING TO SEARCH FOR HERE!"
    5.   end if
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  17. #17
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    Quote Originally Posted by GaryMazzone
    When you open the recordset you perform this code (as I showed you in post number 2):

    VB Code:
    1. if Not tbDepartment.BOF and Not tbDepartment.EOF then
    2.       Do you stuff here
    3.   else
    4.       MsgBox "No Records returned NOTHING TO SEARCH FOR HERE!"
    5.   end if
    Better yet
    Quote Originally Posted by GaryMazzone
    start to learn SQL language
    Then all you would have to do is a SELECT COUNT(*) FROM tablename, and badda bing, you would know how many records are in your table.
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    And badda bing, that required two trips to the database.....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    Quote Originally Posted by techgnome
    And badda bing, that required two trips to the database.....

    -tg
    Not if all he wanted was a count of the records.

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    i've alredy your code and its running now but when i need to add another record its not adding. what will i do

  21. #21
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    Whose code are you running?

    What happens when you try to add another record?

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    84

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    VB Code:
    1. if Not tbDepartment.BOF and Not tbDepartment.EOF then
    2.       Do you stuff here
    3.   else
    4.       MsgBox "No Records returned NOTHING TO SEARCH FOR HERE!"
    5.   end if

    the msgbox "no records forund" is always shown

  23. #23
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: .eof or .bof is true, or current recordset has been deleted. requested operation requ

    The code I should you will not add a new record to the table. It just shows what to do if no records are returned from the table.

    What is the code you are using to add a new record? (I really hope it's not .AddNew and .Update I still think the SQL statements are better to learn).
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width