PRB: CDaoRecordView Toolbar Buttons MalfunctionLast reviewed: June 26, 1997Article ID: Q150122 |
The information in this article applies to:
SYMPTOMSCDaoRecordView depends on an instance of CDaoRecordset to display data. The CDaoRecordView class also needs to stay in synchronization with the current record displayed by the CDaoRecordset instance. Calling the Seek, MoveFirst, MoveNext, or other methods directly on the CDaoRecordset being used by a CDaoRecordView causes the CDaoRecordView to behave incorrectly.
CAUSECDaoRecordView uses four member variables to keep track of bookkeeping information. The first three variables listed below store bookmarks for the first, last, and current record. The fourth variable is used to enable or disable the toolbar buttons corresponding to MoveFirst, MovePrev, MoveNext, and MoveLast.
m_varBookmarkCurrent m_varBookmarkFirst m_varBookmarkLast m_nStatusThese variables are only maintained when the CDaoRecordView::OnMove method is invoked. This method invokes the CDaoRecordset MoveFirst, MoveNext, MovePrevious, or MoveLast methods, and updates the variables. Only OnMove keeps these variables in synchronization. The following list contains the more common CDaoRecordset methods that change the current record:
- Find - Move - Requery - FindFirst - MoveFirst - Seek - FindLast - MoveLast - SetAbsolutePosition - FindNext - MoveNext - SetBookmark - FindPrev - MovePrev - SetPercentPositionWhen the AddNew method is called, a new record is added to the recordset but the current record bookmark does not change. To change the newly added record to the current record, use the following method:
// set the current bookmark to the newly added record m_pSet->SetBookmark(GetLastModifiedBookmark());NOTE: GetLastModifiedBookmark() needs to be called right after the call to Update() to return the newly added record. Calling it after one of the recordview MoveXXXX functions returns a bookmark to the record that was current prior to the move operation.
RESOLUTIONAfter performing a CDaoRecordset method for an instance utilized by CDaoRecordView, reset the CDaoRecordView's bookkeeping variables as shown in the following code:
if (!m_pSet->Seek(...)) { if( !m_pSet->IsEOF() ) { m_varBookmarkCurrent = 1L; // <<- re-initialize m_varBookmarkFirst = // <<- the bookmark m_varBookmarkLast = 0L; // <<- member variables! // Enable toolbar buttons m_nStatus |= AFX_DAOVIEW_SCROLL_BACKWARD;// First & Prev buttons m_nStatus |= AFX_DAOVIEW_SCROLL_NEXT; // next toolbar button m_nStatus |= AFX_DAOVIEW_SCROLL_LAST; // last toolbar button } else { // Move to some valid record } } else { // Seek failed - move to a valid record } STATUSThis behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
REFERENCESFor additional information, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q145686 TITLE : CDaoRecordView Bookmark Members Invalid After Requery() ARTICLE-ID: Q145719 TITLE: BUG: DAOENROL - Can't See Added Records in Windows 95 |
Keywords : kbcode kbusage MfcDAO
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |