I am building a communication/task logging system which logs incoming communications and assigns tasks based on them.
My database has a notes system, so that the users can make notes about a variety of things - e.g. a customer record might have a note which says "This customer always orders their own window frame glass". This is all handled via a single "Notes" table which has a PrimaryNoteTableID which links to a static lookup table which identifies the primary table which the note applies to, and an PrimaryTablePK field which stores the PK of the record within that table it applies to.
In order to avoid corruption, it is advised to keep memo fields in a table of their own with a 1:1 relationship to their parent table (see here), which is what I have done.
When adding new communications and tasks, the user will usually want to add the following:
- Details of the person the communication is with.
- The subject of the communication.
- The type of action required and the deadline for that action.
- A note with details of what has been discussed etc.
With that in mind I have:
tblCommTaskLog with the fields CommDate, ActionRequiredTypeID(FK), ActionDeadlineDays, CommAccountID(FK) etc.
tblNote with: NoteID(PK), PrimaryNoteTableID(FK), PrimaryTablePK(FK), EnteredByUserID(FK), EntryDate.
tblNoteText with NoteTextID(PK), NoteID(FK), NoteText(Memo)
Some of these are foreign keys to other tables which should be self-explanatory.
Essentially what I'm running into problems with is the form for entry with these three tables. I find that the Access handling of subforms can be pretty stupid, such that:
- You're locked into displaying things in a certain way if you want to use a subform, or a subform of a subform.
- Access saves records before you've clicked to save. It also saves records in subforms which can't be handled with a simple "me.undo" in the form's code and results in you having to find the record in the subform and delete it with code.
- The subforms act in stupid ways insofar as the way they assign autonumber PKs and pick those up in the links between child and master forms.
I'd like to just have the fields from tblCommTaskLog and the NoteText field on one form, so that the user fills in the details from tblCommTaskLog (ActionRequired etc.) and the note text, hits a "Save" button, and then via code the items are saved correctly, such that:
- A new record is created in
tblCommTaskLogwith e.g. a PK of72(Autonumber). - A new record is created in
tblNotewith aPrimaryNoteTableIDof4which corresponds totblCommTaskLog, aPrimaryTablePKof72and a PKNoteIDe.g.422(Autonumber). - A new record is created in
tblNoteTextwith aNoteIDof 422.
I think what I need is a main form with the fields from tblCommTask with an unbound text field to take the input for NoteText. I just can't figure out how to create a new record in tblNote, get the AutonumberPK from that field and insert it into the FK of tblNoteText such that everything is linked together correctly with the right FKs. Can I do this with an SQL INSERT and then a SELECT TOP on the Autonumber field? Would I be better off doing this with Recordsets and Lastmodified? Is there some other method I'm not thinking of?