Coding and trapping event for subform add new record

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Noise (Noise_at_tds.net)
Date: 01/17/05


Date: Mon, 17 Jan 2005 23:34:07 GMT

I have a main form and a subform. The main form has all the data for
the parent record. The subform has all the data for the child
record(s). There can be many child records for a single parent record.

I want to always be able to add new parent records. Under given
circumstances I want to allow or restrict when child records can be
created. All that works OK.

My problem is when I am on a parent record where the child record is
not allowed to add new records. If I go to add a new Parent record,
then the child record's subform shows up as a big blank spot. I think
it's because at that time of creating the new parent record, the child
record had AllowAdditions = FALSE, so it won't allow it.

It works fine when I am at a parent record with a child record that
allows additions of new child records.

What I want to do is this: I want to be able to always create a new
parent/child record no matter what is the status of the current child
record.

I could set the subform's property to AllowAdditions = TRUE, but I
don't know where to put the code. I tried putting it on the subform,
but apparently got it wrong. I also tried to put it on the main form
but under which event?

What event will always capture the creation of a new record on the
parent form?

I thought about the CommandBeforeExecute event, but I cannot figure
out how to program it. I was thinking of the following, but don't know
what to do with it.

Private Sub Form_CommandBeforeExecute(ByVal Command As Variant, ByVal
Cancel As Object)

Forms![EnterData_MAIN]![EnterData_SUB].Form.AllowAdditions = True

End Sub

The MSDN technical information talks about it but doesn't tell me how
to actually DO it or where to PUT it or how to implement it.

Anyone have any ideas?



Relevant Pages

  • Re: Main form saving when click on subform??? A97
    ... Child records are normally only allowed (by the relationship ... setting) when related to an existing parent record. ... an existing parent record unless you save the parent upon moving to ... The subform functions as a glorified listbox control. ...
    (comp.databases.ms-access)
  • Re: Delete button isnt working
    ... subform. ... I've done this with no problems on several other databases. ... to delete the parent record as long as child records exist, ...
    (microsoft.public.access.forms)
  • JOIN query: What happens when you delete a row?
    ... Start with two tables, parent records in one and child records in the other, ... Now display fields from that query in a continuous form. ... one of the child records AND THE PARENT record are ...
    (comp.databases.ms-access)
  • SQL update- where problem
    ... I have a parent record with a child record. ... The parent record contains structures and the child records contains ... Am I right in thinking I need the primary key to be equal to the ... I'm hoping that it is just my basic SQL code that is wrong... ...
    (comp.databases.ms-access)
  • Re: Append query - key violations??
    ... i.e. the ForeignKey Field in the Many ... create Child / Many Records without a valid Parent Record. ... related Many / Child Records will be changed automatically to the same value ... Sub-option 2.2 is a bit of a danger as John & I pointed out previously. ...
    (microsoft.public.access.queries)