entry not being saved

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Good evening,

This is a multi-part question.

I have a db in which user enter data, obviously, however, when they close
the application the data they entered on the active record does not get saved?

1. Is there a method to ensure data is committed before closing access?

2. If a user closes access, and not just the active db, does the active
form’s close event get trigerred?

3. Lastly, if I perform a ‘Me.Dirty=False’ on a form, does this implicitly
save all the subform data as well, or do you have to explicitly perform this
command on each and every subform?

Thank you,

Daniel
 
comments inline.

Daniel said:
Good evening,

This is a multi-part question.

I have a db in which user enter data, obviously, however, when they close
the application the data they entered on the active record does not get saved?

1. Is there a method to ensure data is committed before closing access?

if you're entering data into a bound form, the data in the current record is
written to the table as soon as you move off of the record by moving to
another record, moving to a new record, or closing the form. no explicit
Save is necessary.

however...note that if you close the form using code instead of the "X"
button on the top right of the Title bar, AND if the data violates a table
index, the form will close and the record will be discarded without any
warning to the user (this may also occur if a table-level validation rule is
violated, but i couldn't say without testing it). AFAIK, the only way to
avoid this specific situation is to explicitly save the record in the same
procedure that runs the Close action, and then trap the error, so that the
Close action never occurs in those instances.
2. If a user closes access, and not just the active db, does the active
form's close event get trigerred?
yes.


3. Lastly, if I perform a 'Me.Dirty=False' on a form, does this implicitly
save all the subform data as well, or do you have to explicitly perform this
command on each and every subform?

when you move from a mainform into a subform, if the current record in the
main form is Dirty, it will automatically be saved as you "exit" the
mainform and "enter" the subform. the same is true as you move from a
subform back to its' mainform. so if you're "in" the mainform, any
additions/edits you made to data in the subform have already been saved - so
there's no issue of implicitly OR explicitly saving the subform data when
you save mainform data *from within the mainform*.

hth
 
Daniel,

It would normally be expected that the data would be automatically saved
when you close the form or move to another record. If this is not
happening, it probably means that the data entered is not valid in some
way, for example a validation rule has not been satisfied, or a required
field has been left blank, or such like.

To respond to your specific questions...
1. Is there a method to ensure data is committed before closing access?

DoCmd.RunCommand acCmdSaveRecord
2. If a user closes access, and not just the active db, does the active
form’s close event get trigerred?
Yes.

3. Lastly, if I perform a ‘Me.Dirty=False’ on a form, does this implicitly
save all the subform data as well, or do you have to explicitly perform this
command on each and every subform?

There is no answer to this, as it is not possible for a parent form and
a subform to both be dirty at the same time.
 
Answers in-line.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Daniel said:
I have a db in which user enter data, obviously, however, when they close
the application the data they entered on the active record does not get
saved?

1. Is there a method to ensure data is committed before closing access?

The data should be saved be default. In Access 97 or later, if the data
cannot be saved for some reason (e.g. a required field is null, or a
validation rule is not met), the user will receive a message asking if they
want to discard and close, or continue editing.

The only exception to that rule is where you close the form with the Close
action (in a macro) or method (in VBA code.) In that case, Access does lose
your data. More about this bug:
http://allenbrowne.com/bug-01.html
2. If a user closes access, and not just the active db, does the active
form's close event get trigerred?

Yes, the form's Unload and Close events are triggered if the form is open
when the user closes Access.
3. Lastly, if I perform a 'Me.Dirty=False' on a form, does this implicitly
save all the subform data as well, or do you have to explicitly perform
this
command on each and every subform?

Access saves the main form record when the user clicks in the subform, and
saves the subform record when the user clicks on the main form or another
subform. You do not need to explicitly save the subform records unless you
have dirtied them programmatically (i.e. the values have been assigned by
code, even though the subform does not have focus.)

As explained above, you do not need to explicitly save the records unless
you are using the Close method/action.

There is no point saving the record in the form's Unload or Close event,
because the save (or undo) will have already happened by this stage. A form
can never be Dirty when Form_Unload or Form_Close fires.
 

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

Back
Top