Re: Linked Form Not Allowing New Records



Rob wrote:
I have a one to many relationship between two tables: tblCars and
tblParts (One car can have many parts). I created a form using the
wizard and chose "linked forms" instead of "form with subform" when
prompted. The problem Im having is that when entering new records in
the linked form it does not capure the "linked" field from the main
form which causes an error message which reads "Index or primary key
cannot contain a null value". I know access is supposed to "autofill"
that field but its not working. Whats more frustrating is that it
works fine for existing records. I only have a problem during data
entry. Any ideas?

No, Access is only supposed to autofill that field if you choose to build a
form with a subform. Linked forms do NOT provide that feature. All it does
is provide a filter for EXISTING records exactly as you are seeing.

You can solve the problem by setting the DefaultValue property of the second
form to a reference of the first form...

=Forms!FirstFormName!LinkingFieldName

That will mean that you can only use the second form when the first is open
and if you open the second form, navigate to a new record, and then navigate
to a different record on the first form before you fill out the new record
on the second form the new record will still have the linking field from the
record on the first form when it was originally opened. As you can see the
linked form is not as robust as a real subform in this regard. Code can be
added to both forms to solve some of these issues.

You can also make the second form modal so that you have to close it before
you can go back to the first form and change the record on that.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com





.



Relevant Pages

  • Re: Linked Form Not Allowing New Records
    ... Consider using a tab control and putting a subform on each tab. ... That will mean that you can only use the second form when the first is ... record on the first form when it was originally opened. ... Rick Brandt, Microsoft Access MVP ...
    (microsoft.public.access.forms)
  • Re: Linked Form Not Allowing New Records
    ... have too many subforms to fit on one main form and be usable. ... Rick Brandt wrote: ... That will mean that you can only use the second form when the first is open ... record on the first form when it was originally opened. ...
    (microsoft.public.access.forms)
  • RE: Requerying form 1 after creating new record in form 2
    ... After doing a lot more digging in these forums, I found the answer, and ... I automatically opened a second form to enter new records. ... get the second form record to save and b) could not get the the first form to ... then be able to populate the appropriate bound control in frmLast_Updated. ...
    (microsoft.public.access.formscoding)
  • RE: Carrying a field value to another form
    ... Pass the first form's key in the OpenArgs argument of the OpenForm method. ... Refer to a control on the first form to obtain the value. ... I suggest the BeforeInsert event because it fires immediately after the ... > record passed to the second form to select the same record for updating. ...
    (microsoft.public.access.forms)