form save code does not work

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
 
D

Dirk Goldgar

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?
 
J

John W. Vinson

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
 

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