B
BruceM
I have a situation that has proved vexing in several databases. In one
instance, a record is created and a number automatically assigned via code,
then a reason for creating the record is selected, then the summary and the
description are added. Since there could be several reasons for creating
the record, the Reason data are stored in a related table, entered via a
subform. Entering the subform means Access attempts to save the record. I
use a Boolean (form-level variable) to determine whether the Before Update
code runs.
This is the sequence: The user starts a new record by selecting the
department. This generates the record number, and send the user to the
Reason subform. Since it is a new record the Boolean (blnNoVal), which is
False at that point, is set to True in the form's Before Update event, and
the rest of the Before Update code is skipped. If not a new record blnNoVal
remains False, which allows the form's Before Update code to run fully.
Upon exiting the Reason subform blnNoVal is set to False (if at least one
Reason has been selected). The user then enters the Summary and the
Description. This dirties the record, so the form's Before Update code
runs, and all is well.
However, since the form is not dirty after exiting the Reason subform, the
user can navigate to another record, close the database, etc. This means in
some cases a record is created and a number assigned, but that is as far as
it goes. I would like to get rid of the garbage record, but I can't use
Undo because the record has already been saved. Maybe I could delete the
record via DELETE SQL when the user attempts to navigate away from it or
close the database, but I'm not sure where to trap that attempt. I have
User Level Security in the FE and BE of a split database, so I would need to
allow Delete permissions for all users. As long as I keep users away from
the tables and queries it should be OK, but I would rather not do it this
way.
If I could have one Access wish I would have to consider seriously if it
would be not to save the record upon entering a subform. The only reason
this is a problem is that the record is saved before I am ready. It has
been a problem in several databases.
Maybe the solution is to enter the Reason information in unbound controls,
perform the validation, and use code to write from the unbound controls to
the related table if the rest of the validation succeeds.
How do others solve this difficulty?
instance, a record is created and a number automatically assigned via code,
then a reason for creating the record is selected, then the summary and the
description are added. Since there could be several reasons for creating
the record, the Reason data are stored in a related table, entered via a
subform. Entering the subform means Access attempts to save the record. I
use a Boolean (form-level variable) to determine whether the Before Update
code runs.
This is the sequence: The user starts a new record by selecting the
department. This generates the record number, and send the user to the
Reason subform. Since it is a new record the Boolean (blnNoVal), which is
False at that point, is set to True in the form's Before Update event, and
the rest of the Before Update code is skipped. If not a new record blnNoVal
remains False, which allows the form's Before Update code to run fully.
Upon exiting the Reason subform blnNoVal is set to False (if at least one
Reason has been selected). The user then enters the Summary and the
Description. This dirties the record, so the form's Before Update code
runs, and all is well.
However, since the form is not dirty after exiting the Reason subform, the
user can navigate to another record, close the database, etc. This means in
some cases a record is created and a number assigned, but that is as far as
it goes. I would like to get rid of the garbage record, but I can't use
Undo because the record has already been saved. Maybe I could delete the
record via DELETE SQL when the user attempts to navigate away from it or
close the database, but I'm not sure where to trap that attempt. I have
User Level Security in the FE and BE of a split database, so I would need to
allow Delete permissions for all users. As long as I keep users away from
the tables and queries it should be OK, but I would rather not do it this
way.
If I could have one Access wish I would have to consider seriously if it
would be not to save the record upon entering a subform. The only reason
this is a problem is that the record is saved before I am ready. It has
been a problem in several databases.
Maybe the solution is to enter the Reason information in unbound controls,
perform the validation, and use code to write from the unbound controls to
the related table if the rest of the validation succeeds.
How do others solve this difficulty?