I am not
using subforms (but even in the example you provide, I don't see how
it's not possible because saving the main record to disk and
committing the transaction to the database are two conceptually-
distinct entities.).
Because you like presenting a main customer form, and then a "many" lines of
detail for the customer order for example. If you adopt the "save" button
idea, then you users are going to expect the save button to save the whole
form, and including the "many" records on the sub-form.
So, when you click on the invoice details (or tab into he sub form if you
have decent navigation), then you have to save the main form. You are now
able to edit and add "many" sub-form records, and each time you cursor down,
or move to the next sub-form record, you must save the current record. So,
at this point, the main record is saved, and you may have added 4 sub-form
records, and then the user hits the close button you speak of. At this
point, the main record been saved a long time ago, and so have 4 sub-form
records. When the user clicks close, they are expect that save prompt you
talking about. So, you *can* still provide a save prompt, but the conceptual
model you asking for still breaks down (they are not saving the whole screen
as a close..but only the current record of the sub-form could be prompted
for saving).
All I pointing out that if you train and design all your main forms to
prompt the user, this whole concpetial model breaks down if you use a
sub-form. You not going to be albe to un-do those sub-form reocrds, and hte
main reocds was long commited to disk. So, it not that you can't pomropt for
a save, but you going to have to oprt the user when you tab (or click) into
the subform to save the main form, and then for each editng (or even simply
edit + navagation) in those sub-form roecrds, you have to prompt the user.
So, you *can* prompt the user, but hte conicopa model you aksing for does
not work in that case.
And, i not pointing out that what you ask for is somehow wrong, but I just
poting otu that manualla, rpormamogn ernfnece, and vitually everthign you
will read abount ms-access is buuilt on this impled saves concpet. So, even
if we don't like the way it is...it is the way it is!!!
If you want to place a save buttion on your form, you can go:
if me.Dirty = true then
me.Dirty = false
end if
If you want a save prompt for your form, then, then you can place the
follwing code in the forms
before udpate evetn:
If MsgBox("do you want to save?", vbYesNo) <> vbYes Then
Me.Undo
End If
If you want to do it on the close event (barring in mind that if the user
clicked into the sub-form, the record is already saved....and your close
event will not detect that the record is dirty...because it will not be!!!.
If you have a custom save button, then it is easy. However, if the user
closes the application, or the form, then you don't know which is closing
the form (is it the application being closed, or the form). Thus, you can't
really distinguish between the two. And, the un-load event, and the close
event fire well after the record been written to disk. So, unless your using
a custom save button, you can't really provide a save *only* because the
user clicked on the "x" to close the form...