473,424 Members | 1,928 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,424 software developers and data experts.

Passing Master Autonumber ID to SubForm New Record

I have a form "AccountInfo" that contains company names. I have
inserted a subform "Contacts" with contact names and have established
parent/child relationships between the two forms. All works well.

I created an "Add New Contact" command button which passes the
CompanyID (unique key set to autonumber) to the new record. This
successfully works if the parent record (AccountInfo) has at least one
existing contact. But if there are no contacts associated with the
AccountInfo record, I get the error "Application-defined or
Object-defined error" when I click the Add New Contact command button.
This happens because the Contact form CompanyID doesn't have a number
yet---the number is "autonumber".
This is the code I am using:

DoCmd.OpenForm "AddContact", DataMode:=acFormAdd
Forms("AddContact").CmpnyID = Me.CompanyID

How do I pass the parent form CompanyID to the 'Add New' child form?

Nov 7 '06 #1
5 7703
Sounds like you never created a relationship between the two tables.
Try that and then see if that doesn't fix the problem.

Nov 7 '06 #2
pi********@hotmail.com wrote:
Sounds like you never created a relationship between the two tables.
Try that and then see if that doesn't fix the problem.
Relationships already exist with referential integrity.

I can't put my finger on the problem, but somehow I need to pass the
CompanyID from the parent form to the sub-form CompanyID (which is the
field that relates the two tables).

As mentioned, when there is an existing (child) record that matches the
parent company, the CompanyID is successfully passed to the Add Record
function. It is pulling the CompanyID from the already existing
(child) record. The problem occurs only when there is NO existing
(child) record. If no child record exists, there is no CompanyID to
pass to the Add Record function.

I think what I need to do is make the Add Record (for the child form)
look to the parent record for the CompanyID rather than trying to find
it from the child record. But I don't know how to do that.

Nov 8 '06 #3

Swinky wrote:
pi********@hotmail.com wrote:
Sounds like you never created a relationship between the two tables.
Try that and then see if that doesn't fix the problem.

Relationships already exist with referential integrity.

I can't put my finger on the problem, but somehow I need to pass the
CompanyID from the parent form to the sub-form CompanyID (which is the
field that relates the two tables).

As mentioned, when there is an existing (child) record that matches the
parent company, the CompanyID is successfully passed to the Add Record
function. It is pulling the CompanyID from the already existing
(child) record. The problem occurs only when there is NO existing
(child) record. If no child record exists, there is no CompanyID to
pass to the Add Record function.

I think what I need to do is make the Add Record (for the child form)
look to the parent record for the CompanyID rather than trying to find
it from the child record. But I don't know how to do that.
Do you have the LinkChild and LinkMaster fields in the subform set? If
you open the Main form, and then click on the subform inside it, (in
design view), you should see the LinkChild and LinkMaster properties on
the Data tab. Are those filled in?

Nov 8 '06 #4


pi********@hotmail.com wrote:
Swinky wrote:
pi********@hotmail.com wrote:
Sounds like you never created a relationship between the two tables.
Try that and then see if that doesn't fix the problem.
Relationships already exist with referential integrity.

I can't put my finger on the problem, but somehow I need to pass the
CompanyID from the parent form to the sub-form CompanyID (which is the
field that relates the two tables).

As mentioned, when there is an existing (child) record that matches the
parent company, the CompanyID is successfully passed to the Add Record
function. It is pulling the CompanyID from the already existing
(child) record. The problem occurs only when there is NO existing
(child) record. If no child record exists, there is no CompanyID to
pass to the Add Record function.

I think what I need to do is make the Add Record (for the child form)
look to the parent record for the CompanyID rather than trying to find
it from the child record. But I don't know how to do that.

Do you have the LinkChild and LinkMaster fields in the subform set? If
you open the Main form, and then click on the subform inside it, (in
design view), you should see the LinkChild and LinkMaster properties on
the Data tab. Are those filled in?
Yes, the properties has both the Link Parent & Link Child fields filled.

Nov 8 '06 #5

Swinky wrote:
pi********@hotmail.com wrote:
Swinky wrote:
pi********@hotmail.com wrote:
Sounds like you never created a relationship between the two tables.
Try that and then see if that doesn't fix the problem.
>
Relationships already exist with referential integrity.
>
I can't put my finger on the problem, but somehow I need to pass the
CompanyID from the parent form to the sub-form CompanyID (which is the
field that relates the two tables).
>
As mentioned, when there is an existing (child) record that matches the
parent company, the CompanyID is successfully passed to the Add Record
function. It is pulling the CompanyID from the already existing
(child) record. The problem occurs only when there is NO existing
(child) record. If no child record exists, there is no CompanyID to
pass to the Add Record function.
>
I think what I need to do is make the Add Record (for the child form)
look to the parent record for the CompanyID rather than trying to find
it from the child record. But I don't know how to do that.
Do you have the LinkChild and LinkMaster fields in the subform set? If
you open the Main form, and then click on the subform inside it, (in
design view), you should see the LinkChild and LinkMaster properties on
the Data tab. Are those filled in?

Yes, the properties has both the Link Parent & Link Child fields filled.
UPDATE: I think I found the answer to my question. FYI, my code said:

DoCmd.OpenForm "AddContact", DataMode:=acFormAdd
Forms("AddContact").CmpnyID = Me.CompanyID

By changing the 2nd line to read "Forms("AddContact").CmpnyID =
Parent!CompanyID", the ID number is now pulled from the parent record
and inserted into the new child record being created.

Now I can move on to my next challenge :-) .....

Nov 8 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: BillyMac | last post by:
Hi, I had an issue today & yesterday that I had a very difficult time solving and wasn't able to find the solution searching usenet via google. In the spirit of giving back here is how I solved...
1
by: Cesar Zapata | last post by:
Hi, I have a a bound subform and what i'm trying to do is do check if some criteria applies before saving the record and trigger a macro. basically this is what I got. Date Received ...
1
by: Drum2001 | last post by:
Hello All, This seems like it would be simple. Is there a way to have an "After Update" event from Subform1 trigger an "add new record" on Subform2? I see posts to go from Mainform to...
4
by: Ecohouse | last post by:
have a main form with two tabs, and each tab has a subform. The first tab's subform refers to the mainform (this works). The second tab's subform refers to the identity key of the first tab's...
0
by: ApexData | last post by:
I have a subForm sitting on my MainForm. The subForm is a continuous form and Does Not have its RowSource tied to the main Form. If the subform is tested in isolation, outside the MainForm and I...
0
by: paquer | last post by:
Im trying to sort out all subform records except for the new record created via a cmd on the main form. The command creates the new record, autofills some fields, then the PK value is...
2
by: dbstrat | last post by:
Hi. I have 3 tables that I need to display on a master-child form/subform. Think of it as Orders and Order Details. The tables are Orders OrderDetails VendorItems
1
by: pkpanda | last post by:
I have similar but bit different issue that is I have a table INVOICE when user enter data in invoice I have to insert record into Transactions (Master ) and Transaction_details (detail) both...
1
by: farisallil | last post by:
Hi I have a form called Invoice that has a subform called Invoice_datasheet. The subform has the field Customer as the child link and Customer_Name in the Invoice form (The master) as the master...
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?
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.