Adding New Record in Subform

ctgrib

New Member
Joined
Mar 11, 2004
Messages
7
I have a main form (Form_1) with a tab control that has five pages with a subform on each (Subform_1 - Subform_5). Form_1 has no data. Subform_2 through Subform_5 are linked via the child field "RequestID" (number/long integer; foreign key) to the parent field "RequestID" (autonumber; primary key) on Subform_1. Note: in the Link Master Fields box for Subform_2 through Subform_5, I have "forms!Form_1!Subform_2!RequestID" and so on.

What I need: when I open Form_1, I want Subform_1 (first page of tab control) to display where user adds new record. I have this working. Then, when user clicks on one of the tabs for Subform_2 through Subform_5, I want them to be able to enter information on each of these subforms and have it write to the respective tables with the same "RequestID" that was added on Subform_1. Each subform can have multiple records and I have a button on each one to add a new record.

I currently have the subforms (2-5) requery "on current", and it works for the first record, but when I go to add another record on one of the subforms, I get the message "Can't go to the specified record".

Any help is GREATLY appreciated!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I may be confused (easily done with me) but,

Check your relationships. Do you have a One-to-One between SF1 & SF2-5 or is it a One-to-Many?
 
Upvote 0
I have them set up as one-to-many, because for each request ID on subform_1, subform_2 can have multiple entries, and so forth. What should they be set up as?
 
Upvote 0
I would have said One-to-Many allowing duplicates in Sub_Form2-5 but not allowing duplicates in Sub_Form1.

What code do you use behind your 'add record' button?
Are you generating a unique key in :
forms!Form_1!Subform_1!RequestID
 
Upvote 0
I have one-to-many allowing dups in 2-5, and am not allowing dups in 1.

The only unique key I have in subform 1 is RequestID, which is an autonumber. Each RequestID on that form can only have one "entry" or set of information. There is not an "Add Record" button on that form.

The code behind the "Add Record" on subforms 2 -5 is:

DoCmd.GoToRecord , , acNewRec

I was thinking I needed to requery somehow, so I added Me.Requery, and that didn't change anything.

Any ideas? Your help is greatly appreciated!
 
Upvote 0
What happens if you try to goto a new record manualy? either with the menu or paging down after the last entry?

Peter
 
Upvote 0
I'm at a loss to help except to suggest that you try to test the problem with a 'fresh' database. Make a new mdb and copy your tables, setup your relationships.

I'd suggest two ways.
First
sub_form1 fields in the main form
sub-form2-5 as subforms

Second
Mainform
Sub_form1 as subform
sub_form2-5 also as separate subforms

I'm not sure why, but I'm wondering if the problem is because all of your forms (sub_form1-5) are all subforms of a single mainform. Just guessing...

Mike
 
Upvote 0
That actually was the problem. I moved the subform_1 fields to the main form and that corrected it! Thanks again for your help!
 
Upvote 0

Forum statistics

Threads
1,221,645
Messages
6,161,044
Members
451,682
Latest member
ogoreo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top