473,569 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing Master Autonumber ID to SubForm New Record

I have a form "AccountInf o" 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 "Applicatio n-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:=acFor mAdd
Forms("AddConta ct").CmpnyID = Me.CompanyID

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

Nov 7 '06 #1
5 7723
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********@hotm ail.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********@hotm ail.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********@hotm ail.com wrote:
Swinky wrote:
pi********@hotm ail.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********@hotm ail.com wrote:
Swinky wrote:
pi********@hotm ail.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:=acFor mAdd
Forms("AddConta ct").CmpnyID = Me.CompanyID

By changing the 2nd line to read "Forms("AddCont act").CmpnyID =
Parent!CompanyI D", 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
1207
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 it. I have a form with a datasheet subform that is linked by an ID. the parent form has an OnActivate event that does Me!.Requery and when that...
1
4315
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 InStock UnitPrice
1
1983
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 Subform, but not subform to subform. Any suggestions would be greatly appreciated!
4
2798
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 subform. I can't get the second subform to show the proper records. I have used the child and masterlink fields. I have set the recordsource of...
0
1276
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 highlight a record and press the delete key, I get the normal warning that I am about to delete 1-Record. When I Press NO there are no further...
0
1861
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 autoassigned. I want the previous records listed to be filtered out. Although thats what I cant get by. The filter wont work no matter how I put it in. This is...
2
1632
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
2388
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 the tables have ID type autonumber i have a code that insert into record into Transaction table then when I try to insert record into...
1
1982
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 link which means I have 2 tables as well. since my Invoice field is opened by a command button from another form, it is filtered out so that only one...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.