Database Deleting Record Problem

G

Guest

Just launched a new database. Using an Autonumber field to generate document
numbers (sequence is not important - just need a unique identifier). There
are a number of fields that are required fields based on an option group
selection. Problem; If all required fields (they are required fields
programmatically) are not completed and you attempt to exit the form, a
message box appears asking " Do you want to save changes". If you say "Yes"
the form closes, does not save, and the record is deleted - but users are not
aware of this deletion - and they think the record just created is just fine.


Question 1. I thought access saved automatically when you moved focus from
a field or record. Why does a message box appear asking if I want to save
changes? Is there a conflict between the required fields and automatic
saving in access?

Question 2. How do I prevent deletion of records?.

Any help is appreciated.

Thanks
 
A

Allen Browne

A1
The message indicates that the record cannot be saved in its current state.
It is not deleted, because it never was saved.

By definition, you've told Access NOT to save the record if a required field
is Null. So in this case, it cannot perform the default behavior of saving
the record for you.

You're lucky you get a message at all. Years ago, you didn't. Even today, if
you have code in a button that closes the form, the record is silently lost
(no message at all) if it cannot be saved:
http://allenbrowne.com/bug-01.html

A2.
To prevent the deletion of records, set your form's AllowDeletions property
to No.
 
G

George Nicholson

What command is being used to close the form? That message sounds a lot like
the prompt asking if you want to save changes *to the form* not the record.
2 entirely different things, and certainly not what your users would think
they are being asked. As a matter of fact, I don't think Access ever asks
whether u want to save record changes. It always assumes you do and will if
it can. So, unless that message is something added by your own code, I
suspect it's referrung to form changes, not record changes. I suggest you
don't let it ask the question in the first place since its so misleading and
the answer would probably always be "No".

DoCmd.Close acForm, strFormName, acCloseSave

acCloseSave is a vb constant and can have one of 3 values:
acSaveNo
acSavePrompt (default)
acSaveYes

remember, this pertains to changes in the *form*, not the data. I rarely
have this set to anything other than acSaveNo.
In addition to having Form.AllowDesignChanges set to False (i.e., DesignView
only)

Changes to a form design would include a simple change to the recordsource
of a control, something that is done a lot during runtime. If that change
gets saved, that's how the form will open next time. That is rarely
desirable.

HTH,
 

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