FIX: "Operation failed, no current record" Message

ID: Q118759

1.00 1.50 WINDOWS kbprg kbfixlist kbbuglist

The information in this article applies to:

   The Microsoft Foundation Classes (MFC), included with:
    - Microsoft Visual C++ for Windows, versions 1.0 and 1.5

SYMPTOMS

In an MFC database application that uses CRecordsets, open a recordset with a query that will result in at least two records. Call Delete() to delete one of the records. Call Requery() to regenerate the recordset. Now call Edit() or Delete() and you will see something similar to the following in the output window:

    DBMS: ACCESS, Version: 1.1
    Operation failed, no current record.
    Warning: Throwing an Exception of type CDBException
    Error: Un-caught Exception (CDBException)
    AfxTerminate called
    AfxAbort called

CAUSE

This message occurs because Requery() does not reset the m_bDeleted variable that is set when you call Delete(). When you call Edit() or Delete() after the Requery(), m_bDeleted is checked and if it is TRUE, the application assumes that there is no valid current record.

RESOLUTION

To correct the bug, override CRecordset::Requery() in your derived CRecordset class and reset the m_bDeleted member to FALSE. In the "MORE INFORMATION" section, below, is an example of an overridden Requery().

STATUS

Microsoft has confirmed this to be a bug in the Microsoft Foundation Classes, versions 2.0 and 2.5. This bug was corrected in MFC version 2.51, included with Visual C++ version 1.51.

MORE INFORMATION

Sample Code

   // CMyRecordset is derived from CRecordset.

   BOOL CMyRecordset::Requery()
   {
       m_bDeleted=FALSE;
       return CRecordset::Requery();
   }

Additional reference words: 1.00 1.50 2.00 2.50 record set KBCategory: kbprg kbfixlist kbbuglist KBSubcategory: MfcDatabase
Keywords          : kb16bitonly kbDatabase kbMFC kbODBC kbVC kbbuglist kbfixlist
Version           : 1.00 1.50
Platform          : WINDOWS
Solution Type     : kbfix

Last Reviewed: September 21, 1997