By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,081 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Problem creating new records in a subform

Rabbit
Expert Mod 10K+
P: 12,347
I have a tbl_Demo that is linked one to many to tbl_Services on DemoID.
I have a form for tbl_Demo with a continuous subform for tbl_Services.
Referential Integrity is turned on.

Before ever going into frm_Demo, there is an intermediary form with a button that first checks for overlaps and such. The button then opens frm_Demo and populates a couple of fields. It also needs to create 16 records to start out with in the subform.

I can't use DoCmd.GotoRecord , , acNewRec. Something about how I can't use that on a form in Design View.

I can't use DoCmd.GotoRecord , "frm_Sub_Services". Says that it's not open.

I tried to do it through the subform's recordset clone but it says there needs to be a related record in tbl_Demo. Then again, I didn't set the value of tbl_Services.DemoID to match tbl_Demo.DemoID. But the whole point of referential integrity was to avoid this.

Is there another method?
Mar 14 '07 #1
Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,619
I have a tbl_Demo that is linked one to many to tbl_Services on DemoID.
I have a form for tbl_Demo with a continuous subform for tbl_Services.
Referential Integrity is turned on.

Before ever going into frm_Demo, there is an intermediary form with a button that first checks for overlaps and such. The button then opens frm_Demo and populates a couple of fields. It also needs to create 16 records to start out with in the subform.

I can't use DoCmd.GotoRecord , , acNewRec. Something about how I can't use that on a form in Design View.

I can't use DoCmd.GotoRecord , "frm_Sub_Services". Says that it's not open.

I tried to do it through the subform's recordset clone but it says there needs to be a related record in tbl_Demo. Then again, I didn't set the value of tbl_Services.DemoID to match tbl_Demo.DemoID. But the whole point of referential integrity was to avoid this.

Is there another method?
Rabbit:
I'm not exactly sure if this is what you were requesting, but I'll give it a shot anyway. The following code will:
__1. Save the Parent Record in frmDemo.
__2. Set Focus to the Sub-Form Control.
__3. Add a New Record to the Sub Form frm_Sub_Services. You need never explicitly mention this Sub Form by Name, only its Container.
Expand|Select|Wrap|Line Numbers
  1. __1. SendKeys "+{ENTER}", True
  2. __2. Me![<sub form control name>].SetFocus
  3. __3. DoCmd.GoToRecord , , acNewRec
NOTE: I'm probably totally off track but please let me know if this is what you were trying to accomplish.
Mar 15 '07 #2

Rabbit
Expert Mod 10K+
P: 12,347
Rabbit:
I'm not exactly sure if this is what you were requesting, but I'll give it a shot anyway. The following code will:
__1. Save the Parent Record in frmDemo.
__2. Set Focus to the Sub-Form Control.
__3. Add a New Record to the Sub Form frm_Sub_Services. You need never explicitly mention this Sub Form by Name, only its Container.
Expand|Select|Wrap|Line Numbers
  1. __1. SendKeys "+{ENTER}", True
  2. __2. Me![<sub form control name>].SetFocus
  3. __3. DoCmd.GoToRecord , , acNewRec
NOTE: I'm probably totally off track but please let me know if this is what you were trying to accomplish.
Not quite what I was looking for. The code is actually running from another form so I can't use Me. I tried to set the focus to it using Forms!frm_Demo!frm_Sub_Services.SetFocus but it says I can't set focus to that control.
Mar 15 '07 #3

Post your reply

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