Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting a null valuein the subforms?

Status
Not open for further replies.

DBritter

Technical User
Jun 28, 2000
37
US
This is the error that I get when I open a form in data entry mode: "You tried to add a new record but didn't enter a value in the field that contains the primary key."

The primary key that i have on the form is an autonumber which in not enabled. there are two subforms on this form and the error happens twice right after the first field(entering the company name) loses its focus.
What I am asking for is a way to open this form in dataentry or at least to appear in data entry to the user without all the errors popping up.
Thanks
 
That's because for some reason the primary key of your form's underlying table is not updating.Check and confirm that the primary key of this table is actually set to an autonumber.I'm assuming you get this error on your main form.
 
Presumably your autonmuber field is disabled to prevent the users from trying to enter data into it. BUT...Wouldn't the fact that your Autonumber field is disabled prevent it from updating at all?

Try enabling the field and set the Lock property to Yes instead. This prevents users from entering data in the field, but still allows Access to update the field automatically.

HTH
Lightning
 
or another suggestion is to make the field invisible. ruth.jonkman@wcom.com
 
I have made all of the index numbers enabled and locked but the same error occurs.
When the form first opens "(autonumber)" is written in the field [LeadID]. After the first field[CompanyName] is updated the field has a value[LeadID], but the subforms do not contain the value in the [LeadID] fields.
Shouldn't these be updated when the parent form is updated?

The error stops occuring only after I imput data in the subform and the [LeadID] field is populated.
 
Now I am also noticing another problem: When I open the form on its own and try to add a record, the subforms are not visible they are just grayed out boxes. How can I get the forms to stay visible.
 
Are the tables/queries that your main form and subforms have as their RecordSources related in a one to many relationship?. If so, view your main form in design view and delete your subforms from them. Then add them again onto your form.If this relationship is established, Access will automatically ask you what fields you would like to use as the linkcriteria between your forms basically the primary and secondary keys)
Also, go to your data entry form's property sheet and select the Data tab.Set the Allow filters,edits,deletions and additions to Yes then set the Data entry option to No.
Set a control on your form and have its control source set to the autonumber.Make this visible and observe its behaviour when doing your data entry.
 
Ooops I missed something. Before doing the above steps, make sure that the table/query which your subform is using as its rowsource, contains the primary(actually the foreign key) key of the table your main form is using.Delete you subform from your main and then re-add it again.Access will prompt you for a link field.Select this foreign key and follow through the steps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top