al*****@cox.net wrote in
news:er********************************@4ax.com:
HI--what I am trying to do is 2 things:
1. Open a form in either data entry mode or edit mode depending on
what task the user is performing
2. Cancel events tied to fields on the form if I am in edit mode.
The reason I want to do this is becasue when entering a new record
the form is entered in data entry mode and I have lots of stuff
happening upon entering and leaving fields. In edit mode I do not
want the events to fire.
I would like to avoid making a second set of forms for editing if
I can avoid it
That's precisely why I tend to use a different form for adding
records than for editing, because you can end up with massive
convolution trying to handle two often contradictory sets of
requirements in one form.
The key is this;
Your New Record form need not be identical. All it needs to have is
the minimal set of fields required to create a valid record. Once
those are populated on the New Record form (which should be unbound,
so that it's easy to cancel the addition without needing to undo an
insert), insert the record in code using a recordset with the
argument dbAppendOnly (Set rsAdd = db.OpenRecordset(strSQL, ,
dbAppendOnly), then add the values from the unbound form to the
fields of the recordset, and record the new record's primary key
value (I'm assuming an AutoNumber PK). Use that PK value to open the
new record in your regular data editing form so the user can
complete any additional data entry.
Years ago I struggled with trying to do what you're attempting, as
well as trying to maintain identical appearing forms, one for add
and one for edit. I ran into just the kind of problem you're
encountering, plus the annoyance of having to delete a record (and
losing PK values in AutoNumber fields) when the Add was cancelled by
the user.
The unbound form with the subset of required fields only avoids all
those problems and allows you to optimize the two forms for the
completely separate purposes.
Of course, the hardest part may be deciding which fields really are
the required fields, i.e., the ones that you have to populate in
order to create a valid new record. But in a properly-designed data
schema, that should already be part of the design of the table. If
it's not, then your schema is incomplete.
The other advantage to this approach is that you can put any
duplicate checking code behind this form, instead of relying on mere
index collisions to catch dupes. The reason I use the adjective
"mere" is because indexes are dumb in terms of identifying dupes --
they only trigger when the data in a second record is entered
identically, whereas close records may want to be scrutinized by a
human being for possible duplicate status. Simple example: Is Bill
R. Smith a duplicate of the existing record William R. Smith? Can't
check for that with indexes, but you sure can with code, and having
it behind a dedicated New Record form makes it easy.
--
David W. Fenton
http://www.bway.net/~dfenton
dfenton at bway dot net
http://www.bway.net/~dfassoc