I may be overthinking this, but I see all sorts of potential problems....
I have a table that I'll call Master. Among other items, it contains a field called Serial. I thought this would be a static item--i.e., that it would never change (once initially assigned), for any given row in Master. I now find out that it can change, and not only that, I need to store history of those changes.
I can break Serial out into a separate table, where each row will have a MasterId, EffectiveDate and Termination Date (the current Serial for a Master row would be the one (and only one--code-enforced) row with a Null TerminationDate). So far, so good....
Now the problem that I'm asking about: I have a bound form built on a Select from Master that includes Serial.
What I think I want to do, to make this changeability transparent to the user, is to short-circuit any changes that are made to the Serial text box, probably in the text box BeforeUpdate event. I'd then use code to Terminate the current row in the Serial table & insert a new row, which becomes current and is displayed in the text box. I would (I think) need to cancel the update in the form's recordset, without losing any changes the user has made to other fields....
It's at this point that my brain goes out to lunch, since I'm still much more comfortable with unbound forms & Save buttons. Can I do this, as proposed? What tricks & traps do I need to know about? If need be, I can make the Serial field on the form read-only, and require a pop-up to edit it, but I'd rather avoid that if I can.
**EDIT
Hope this helps:
Before
table Master
Id AutoNumber PK
Serial Text(20)
--other fields
Current frmMaster RecordSource:
SELECT Id, Serial, yada, yada FROM Master WHERE blahBlah
After
table Master
Id AutoNumber PK
--other fields
table Serial
Id AutoNumber PK
MasterId Long
Serial Text(20)
EffDt Date/Time
TermDt Date/Time
New frmMaster RecordSource:
SELECT Master.Id, Serial.Serial, yada, yada
FROM Master LEFT JOIN Serial ON Master.Id = Serial.MasterId
WHERE Serial.TermDt is Null AND blahBlah
An "edit" on the form should result in:
- Selected row in Serial gets TermDt filled (Now()). NO CHANGE is to be made to the value of Serial.Serial on this row.
- A new row in Serial is created, with new Serial, same MasterId and EffDt = Now()
- New Serial displayed on form, preferably such that it looks to the user as if they'd just edited in place.
- Any changes made to other fields on the form get saved.
EDIT, again
Okay, so HansUp has given an answer that looks like it covers most of what I need. My remaining stumbling block may not even be an issue (though if that's the case, can someone explain why?).
The use case of adding a Master is pretty straightforward, but in the use case of an update that changes the Serial I'm still confused: if txtSerial
is bound to Serial.Serial
, and the user changes the contents of txtSerial
, won't Access attempt to Update the contents of Serial.Serial
to match? How does Adding a Serial row on change (which looks like it should work a treat), prevent the Update of the existing Serial row?