form save code does not work

  • Thread starter Thread starter gator
  • Start date Start date
G

gator

I have code that is supposed to automatically save the form when it is
closed. But, why am I being prompted to save when I close? I am closing
using the 'x' in the top right corner....here is the code....

Private Sub Form_Close()
DoCmd.Save acForm, "Deposits"
End Sub
 
gator said:
I have code that is supposed to automatically save the form when it is
closed. But, why am I being prompted to save when I close? I am closing
using the 'x' in the top right corner....here is the code....

Private Sub Form_Close()
DoCmd.Save acForm, "Deposits"
End Sub


What exactly do you have in mind when you say "save the form"? If the form
is bound and the current record has been modified, it will be saved
automatically when the form is closed, provided there's no reason it can't
be. Your code, if it worked, would save design changes to the form, not
data. Is that what you had in mind?
 
I have code that is supposed to automatically save the form when it is
closed. But, why am I being prompted to save when I close? I am closing
using the 'x' in the top right corner....here is the code....

Private Sub Form_Close()
DoCmd.Save acForm, "Deposits"
End Sub

This can be confusing. The "Save" method saves *design changes to the
structure of the form*. I'm guessing that you want to save the record to disk.
It's usually not necessary to do so in the Close event - the record is in fact
automatically saved for you when you close - but if you wish to do so in code,
use either of the following expressions:

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty Then
Me.Dirty = False
End If
 
Back
Top