PRB: CDaoRecordView Toolbar Buttons Malfunction (150122)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2b
- Microsoft Visual C++, 32-bit Professional Edition 4.2b
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q150122 SYMPTOMS
CDaoRecordView 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.
CAUSE
CDaoRecordView 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_nStatus
These 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 - SetPercentPosition
When 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.
RESOLUTION
After 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
}
STATUS
This behavior is by design.
REFERENCES
For additional information, please see the following articles in the
Microsoft Knowledge Base:
145686 CDaoRecordView Bookmark Members Invalid After Requery()
145719 DAOENROL - Can't See Added Records in Windows 95
Modification Type: | Major | Last Reviewed: | 12/8/2003 |
---|
Keywords: | kbcode kbDatabase kbprb kbusage KB150122 |
---|
|