Sam Kuo said:
The data-entry subform now works great.
Excellent!
The 2nd subform (sfSubList)
is in datasheet view --with AllowAdditions = No, so user is forced to
use the data-entry subform for adding record.
Because I'd like all toolbars to be hidden (and have done so). I'm
hoping to have a cmdUndo that undo the last input (just like the
default undo) and a "delete" button that deletes any selected record
in 2nd subform. How code does the jobs? Can buttons be placed in main
form (because they won't display in datasheet view)?
A Delete button shouldn't be a problem, but I'm not sure about the Undo
button. I can think of several different circumstances in which the
user might want to "undo":
1. After beginning to enter a record on the data-entry subform, but
before saving it, the user might decide to discard this unsaved record.
In this case, at least, the Undo button would have to be on the subform,
not the main form. Note that the user can press the {Esc} key to
undo -- first the current control, then the form.
2. After saving a record from the data-entry subform, the user might
want to "undo" it. In this case, undoing the record would require
deleting the most recently saved record. The command button to
accomplish this could be on the main form or the subform; it doesn't
matter.
3. While editing a record on the "list" subform (since it allows edits),
the user might want to undo the changes made, before the record is
saved. This is a true "undo" operation, but there's a problem with
using a button for it. The button can't be on the subform, if the
subform is in datasheet view, because the button won't be visible. But
the button can't be on the main form, because transferring the focus to
the main form will force the subform to save its record, and so it won't
be "undoable" any more. Working around this obstacle will be
complicated. Again, note that the user can press the {Esc} key once or
twice to undo the changes made to the current record.
4. After editing a record on the "list" subform and saving it, either
explicitly or by sending the focus to the main form or to the data-entry
subform, the user might want to undo the changes that he made (and
saved) and restore the record to the values it had before it was edited.
The only way to do this would be to record the pre-edit field values of
the most recently edited record, saving them in a collection perhaps,
before the record is saved. Then it would be possible for code behind a
button to update that record and set it back to its original values. As
you can see, this is not a trivial business.
5. After deleting a record on the "list" subform, the user might want to
restore it. Handling this would be similar to restoring a saved record
to its pre-edit values.
So, seeing what's involved here, it's up to you to decide which, if any,
of these various "undo" features you want to provide. The code could
get pretty elaborate for some of them, and I don't think I have the free
time to write it all for you.