I have been playing with this in one of my subform databases and discovered that there is a way to accomplish what I believe you were trying to do - learned something new!
What I found is that, if you set the focus to the subform container, use the
DoCmd.GoToRecord record:=acNewRec
to move to a new record in the subform, you can then set the control's value to whatever is valid for the control, finally check the subform to see if it is "dirty" and if so save the newly created record.
Normally I don't just post code; however, this is something I've never tried before and appears to have some value:
In this case, I was simply entering an arbitrary value for a new "child" in the child subform for the current parent using a command button...
- Private Sub zctrl_cmd_addachild_Click()
-
Dim zSfrm As Form
-
'
-
'strictly speaking, one doesn't need to create the form object; however, this way there's less chance for typos
-
'
-
Set zSfrm = Me!zctrl_sfc_Child.Form
-
'
-
'Here You have to reference the sub-form-control that contains the actual sub-form... I always rename these controls
-
Me!zctrl_sfc_Child.SetFocus
-
'
-
'now that the sub-form has the focus, move to the new record
-
DoCmd.GoToRecord record:=acNewRec
-
'
-
'enter the value you want for the control (or the field in the recordset of a bound form)
-
'I suggest referencing the control - this way we're sure that we're acting on the form!
-
'probably should add code to verify that we're actually on a new record in the subform; however, I leave that for the developer.
-
zSfrm.zctrl_txt_child_name = "cmd_" & Format(Now(), "yymmddhhnnss")
-
'
-
'check to see if the subform has an edit and save if so
-
If zSfrm.Dirty Then zSfrm.Dirty = False
-
'
-
'NORMALLY, you'd want error trapping in this code
-
'however, just for the demo, I'll simply clear the object
-
Set zSfrm = Nothing
-
End Sub
I've tried the above code and it works in my database (Access2013 both in Win7 and Win8.1) I believe that the reason this works is because we're acting directly upon the form which still has scope for the Master/Child field relationships established at the form level; thus, Access knows to create the related field entries for the new record.