473,385 Members | 1,707 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,385 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 7696
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.