Following up on my question from July 21, 2018 (which June7graciously helped me with) about opening a form to add a new record ….
That situation was pretty straight forward as I was simplyadding a new record to a table with no “parent relationship” above it. This time I want to add a new record to atable that has a “child relationship” and that relationship link needs to bepart of the add new record procedure.
There is an Events table (primary key EvtID) which storesinformation about a food drive event. There is a Collections table (primary key ColID) which storesinformation about food collections from a food drive event. The Events table has a one-to-manyrelationship with the collections table as there may be more than one food drivepick up during an event. The collectionstable has a foreign key named EvtID which establishes the relationship betweenthe two tables.
There is an Event Detail form (form view) with a Collectionssub form (datasheet view), which contains only the ColID primary key number,the linked EvtID number (hidden), collection date, and pounds collected. Ifthere are already collections records one can click on the ColID field of aparticular record and a Collection Detail form opens up in form view. This form contains all the fields from theCollections table and is what one uses to record all the information about thatfood drive collection.
If a new collection record for an event needs to be added,regardless if it is the first collection record for the event or an additionalone, rather than going to the (New) line of the collection datasheet sub form,putting in a date, saving the record (ctrl + s), then clicking on the ColID ofthe new record to bring up its Collection Detail form, this is what I wouldlike to do, but can’t figure out:
I would like to have a command button labeled “Add NewCollection Record”. When clicked I wantthe button to open a new collections table record in form view so that a newcollection associated with the linked event can be added.
I don’t know if I should use a macro, or some other type of “code”for this. I have used macros before toopen a form, and to create a new record, but in this situation the newcollection record has to also have an association with an event … that is, whena new blank Collection Detail form opens its EvtID field (the Collections table’sforeign key which links it to the Events table) needs to be populated with thesame number showing in the Event Detail form’s EvtID field (the Events table’sprimary key).