Subform entries

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am posting my problem again because I did not get an answer yet and it has
been a few days. I read often that you do not like multi postings but I
still have not solved my problem. So thanks for your patience.

I have a subform that is linked to the main form by an aggregate chain
number. The subform is based on a query of 2 tables (history Table and
Account # Table) joined by the chain number also.
When I try to enter information in the subform, I get an error message
saying that the index or primary key cannot have a null value and my
information is never entered. At first the chain # field is blank, but after
I start to insert text it popluates itself. The problem must be that I am
not actually updating the History table with that chain number. Should I
have a event procedure for this problem? Maybe an "on load" event?? If so
please tell me how to right the code for it. I am new to Access and my
knowledge is very basic.
Thanks.
 
The symptoms you describe sounds like a problem that Access has with
handling default values.

The subform is based on a query with 2 tables. If the error occurs when
adding a new record in the subform, make sure that you are trying to create
the entry in the fields from ONE of the 2 tables only. In general, you won't
be able to create new entries in 2 different related tables simultaneously.

If that's the case, then open the other table (the one you are NOT creating
the entry in), and check if any fields have a Default Value set. If so,
Access will (wrongly) apply the default value in your subform, and attempt
to create the new record in that table also. Of course that fails, because
the foreign key is not present, and so you received the error message you
described.

To fix the problem, delete the Default Value from each of the fields in the
lookup table. You may also need to check the Default Value of the text boxes
on the form, again removing them from any of the fields bound to the lookup
table.

Other possible causes of the problem:
- Your main form is at a new record when this happens.
- There is another lookup field in the table you are writing to that has
zero as the default value.

HTH
 
Hi,
when you try enter a new record in subform, first the record in the master
table (in the master form) must exist already.

that means, you must first enter something in the master form, when the
subform has focus, the master record will save automatically, now you can
work with the subform.

when you enter something in the subform, access create a new record for the
"child table" and the link field of this subform will have the value of the
master link field, in your case this field (or control) is still NULL

This is a normal situation of Form wiht Subform, which are bound to Master
and child table, between them is a relation with "enforce Referential
Integrity"

I hope, it can help you. When not, send me the database.

Martin
 
Thanks for the help. I checked each table and the default values were blank.
I appreciate your time. I may never find out my problem.

Catherine
 
Back
Top