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
 
A

AccessVandal via AccessMonster.com

Use

DoCmd.Close acForm, "Deposits", acSaveYes

to close the form without propmting.

Whatever your reasons for saving the form depends on the view the form where
you allow the form to be modified until the form becomes unacceptable for the
each users. Even allowing deleting of controls is unacceptable, you may want
to review this.
 

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