473,416 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Form/subform and referential integrity

How do I maintain referential integrity between a main form and a subform, each based upon different (but joined with integrity enforced) table?

Here's the situation:
I have two tables: tblContracts and tblPayments. tblContracts has an autonumber field called IDKey as its primary key. tblPayments also has an IDKey field (Integer datatype). The two tables are linked in a one-to-many relationship on the field IDKey with referential integrity enforced.

I have a main form based upon tblContracts (the "one" side of the relationship) that has an embedded subform based upon tblPayments. the two forms are linked Parent/Child on the IDKey field.

Here's the problem: If a user goes to a new record in the main form, it allows them to enter information in the subform without entering information in the main form. This means that a new record (and its corresponding autonumber IDKey field value) does not get generated in tblContracts and I have an orphan record in tblPayments that is not linked to any record in tblContracts - which violates the referential integrity that is supposedly enforced between the two tables.

Any guidance on how to deal with this would be greatly appreciated.

TIA,
Carolyn
Aug 3 '06 #1
6 4475
comteck
179 100+
Everything seems to be set up ok. Check to make sure you are including the IDKEY on both forms. You can even hide those fields if you want, but I'm pretty sure they should be there. Since the IDKEY on the main form is an autonumber, it should then create that same IDKEY on the subform, due to the parent/child link.

comteck
Aug 3 '06 #2
That's exactly what I would have thought, but it does not appear to work that way. The tables are linked in the relationships window with referential integrity enforced for both cascade update and cascade delete. The IDKey field appears on both forms and is used to link the main form to the sub form. IDKey is the primary key for the table on which the main form is based.
Anyway, the workaround I am using is to make the subform invisible until something is entered on the main form. Not my first choice for usability, but at least it keeps the integrity of the table relationships.
Any further thoughts would be welcome.
Carolyn
Aug 4 '06 #3
comteck
179 100+
In your "tblPayments" table, is the datatype a Number or an Autonumber? It should be Number.

I'm assuming you don't get a message that says "Index or Primary Key cannot contain a null value."

Like you, I'm baffled with this one.

comteck
Aug 4 '06 #4
Hi, again.

The data type of the IDKey field in tblPayments is Integer.
No error message. (Actually, the error message you indicate is the error message I would have expected.)

I've tried setting this up in a bitsy test DB as well as my larger application just to make sure there wasn't something else weird going on.

The test DB has two tables: tblContracts (with two fields: IDKey as primary key, autonumber, and Contracts as a text field) and tblPayments (also with two fields: IDKey as Integer and Payments as a text field.) The tables are set up in the Relationships window as a one (tblContracts) to many (tblPayments) relationship with referential integrity enforced.

Then I created two forms: frmContracts with the two fields from the Contracts table and a subform, frmPayments with the two fields from the Payments table and linked the two together on IDKey.

If you go to a new record in frmContracts and only enter information in the Payments subform, and then close the form, you'll wind up with an orphan record in the Payments table.

It's a puzzlement...
Aug 4 '06 #5
comteck
179 100+
Integer is not a data type. It is selected under "Field Size". The data type can be either "Autonumber", or "Number", and Integer can be selected for either.

While in the table design view, you select a "Field Name", and directly to the right of that, you select the datatype. For the main form, the datatype should be Autonumber, and for the sub-table, the datatype should be Number.

As well, I've always selected "Long Integer", as opposed to "Integer". It shouldn't make a difference though.

comteck
Aug 4 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
IDKey should be a foreign key in tblPayments not a primary key. There should be a separate primary key in tblPayments unique to it. Try this and see if it makes any difference
Aug 8 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Steve | last post by:
In AccessXP in Access2000 mode --- TblCustomer: CustomerID, CustomerName TblOrder: OrderID, CustomerID, OrderDate TblOrderDetail: OrderDetailID, OrderID, Detail Appropriate...
0
by: Steve | last post by:
For all who might have read my previous posts ---- AccessXP in 2000 mode and I presume in 2002 mode has a bug you might not know about. If you try and delete a record in a subform where...
4
by: Don Seckler | last post by:
I am building an application to track the distribution and returns of copies of magazines. Copies of a magazine that are unsold are returned by the retailer to the wholesaler. They are...
2
by: Bob Rogers | last post by:
I seem to have gotten myself into a bit of a pickle. I am trying to delete a record from a table attached to a form, and it complains about not being able to delete a record in a table because...
3
by: Dave | last post by:
I have always taken it for granted that once RI is in place, no orphan records can be created, and that RI can't be put in place while orphans exist, but today I came across a situation where that...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
80
by: Andrew R | last post by:
Hi I'm creating a series of forms, each with with around 15-20 text boxes. The text boxes will show data from tables, but are unbound to make them more flexible. I want the form to be used...
11
by: AndyM | last post by:
Hi, I have a curious problem that is causing me large amounts of grief and is steadily turning me grey. Hopefully you guys can help. I have a Master table that contains a CustomerID (as well as...
2
by: ApexData | last post by:
Access2000, using a continuous form. I’m getting a message that say “you cannot add or change a record because a related record is required in table Employee”. This occurs in all my combobox...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.