Why/when does close save?

O

OceanView

You're in a record, change a field, then close the form. The record
gets saved automatically. Is there a way to prevent this? And how
do I catch it? A form_close event doesn't seem to work because
me.dirty =false. Would you have to do a confirm on *every* before-
update event?
 
L

Larry Linson

The Form has a BeforeUpdate event in which you can set Cancel to cancel the
update. Close will save the Record if anything has been modified, e.g., the
Form is Dirty.

Larry Linson
Microsoft Access MVP
 
O

OceanView

The Form has a BeforeUpdate event in which you can set Cancel to
cancel the update. Close will save the Record if anything has
been modified, e.g., the Form is Dirty.

Larry Linson
Microsoft Access MVP

Yes, I know that. But I Want to know if that's happening because the
form is closing. I suppose I can disable the close box and force
them to use close button control, but that seems clumsy. Is seems
like the events happen in the wrong order.
 
P

Peter Smith

OceanView said:
Yes, I know that. But I Want to know if that's happening because the
form is closing. I suppose I can disable the close box and force
them to use close button control, but that seems clumsy. Is seems
like the events happen in the wrong order.

I use one of these:
+++++++++++++++++++++++++++++
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Response
If Me.Dirty = True Then
Response = msgbox("Do you want to save the changes?", vbYesNo)
If Response = vbYes Then
'do nothing
Else
Me.Undo
End If
End If
End Sub
+++++++++++++++++++++++++++++

HTH

- Peter
 
B

Bruce M. Thompson

The Form has a BeforeUpdate event in which you can set Cancel to
cancel the update. Close will save the Record if anything has
been modified, e.g., the Form is Dirty.

Larry Linson
Microsoft Access MVP
[...]


Yes, I know that. But I Want to know if that's happening because the
form is closing. I suppose I can disable the close box and force
them to use close button control, but that seems clumsy. Is seems
like the events happen in the wrong order.

Closing the form will cause the "BeforeUpdate" event to be fired as will moving
to another record or moving between a main form and subform (and you likely knew
that, too). What you perceive as clumsy is actually a commonly used approach for
controlling user activities at both the form level and the application level.
The order in which the events occur is by design and works best for those who
need to make use of them. For more information on the order of events, see:

http://msdn.microsoft.com/library/d...ce97/html/managingeventsinyourapplication.asp

.... and Access Help.
 
D

Dirk Goldgar

Peter Smith said:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Response
If Me.Dirty = True Then
Response = msgbox("Do you want to save the changes?", vbYesNo)
If Response = vbYes Then
'do nothing
Else
Me.Undo
End If
End If
End Sub

Pardon me, but that "If Me.Dirty = True" test doesn't seem to me to make
sense. If the form's BeforeUpdate event has fired, the form *must* be
dirty.
 
O

OceanView

The Form has a BeforeUpdate event in which you can set Cancel
to cancel the update. Close will save the Record if anything
has been modified, e.g., the Form is Dirty.

Larry Linson
Microsoft Access MVP
[...]


Yes, I know that. But I Want to know if that's happening
because the form is closing. I suppose I can disable the close
box and force them to use close button control, but that seems
clumsy. Is seems like the events happen in the wrong order.

Closing the form will cause the "BeforeUpdate" event to be fired
as will moving to another record or moving between a main form
and subform (and you likely knew that, too). What you perceive
as clumsy is actually a commonly used approach for controlling
user activities at both the form level and the application
level. The order in which the events occur is by design and
works best for those who need to make use of them. For more
information on the order of events, see:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
office97/html/managingeventsinyourapplication.asp

... and Access Help.

I guess what I meant by clumsy, is that there doesn't seem any to
trace the event chain, so that, in before_update I can tell whether
the record is being updated because they are changing records, or
because the form is closing.

But thanks for the help, folks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top