The Refresh command cancels add mode, if the user had previously clicked Add, or it discards any changes the user may have made on the form for the current record. In the first case, DaoEnrol cancels add mode by calling:
CDaoRecordset::Move(0);
When you call AddNew to begin the add operation, the framework stores a copy of the current record’s fields before allowing the user to enter new values in the record view’s controls. Calling Move as shown here “refreshes” the current record — and effectively cancels the add operation. It restores the record that was current before add mode began. This also works if you called Edit instead of AddNew.
When the user cancels add mode, DaoEnrol makes the Section control read-only again, for reasons explained earlier.
To implement the Refresh command
OnRecordRefresh
starter handler in class CSectionForm
.if (m_bAddMode)
{
m_pSet->CancelUpdate();
m_pSet->Move(0);
m_ctlSection.SetReadOnly(TRUE);
m_bAddMode = FALSE;
}
// Copy fields from recordset to form, thus
// overwriting any changes the user may have made
// on the form
UpdateData(FALSE);
You are now ready to build and run Step 3 of DaoEnrol. Try the new Add, Refresh, and Delete commands. Try forcing the two exceptions handled by DaoEnrol — deleting a section that has Enrollment records, or adding a duplicate section.
This concludes the Step 3 of the DaoEnrol tutorial.