I have been using the function DoCmd.GoToRecord , , acNewRec
successfully for creating and moving to a new record within a subform (with a table as the source). However, when I try to do the same from the parent form, this does not work. I have tried different approaches, including:
Me.sbfrm_subform.Controls("ctrName").SetFocus
DoCmd.GoToRecord , , acNewRec
which only sets the focus on the control (ctrName), but fails to add and go to a new record, or
DoCmd.GoToRecord acDataForm, Me.sbfrm_subform.Form.Name, acLast
Which returns the runtime error 2489, "The object 'sbfrm_subform is nt open."
Try placing the code into the subform and then call it from the Parent:
Sub Form Code:
Sub GoToNewRecord()
DoCmd.GoToRecord , , acNewRec
End Sub
Parent Form Code:
Me.sbfrm_subform.GoToNewRecord
This looks like a very elegant solution, but I cant make it work. I specifically go to the subform code, put the Sub GotoNewRecord() in there, and then try to access it from the main form (Me). It does nt recognize the sub, and gives a compile error (expected :=). I made the sub Public as well, but did nt help. I m curious what am I doing wrong.
Apologies. The parentheses is probably what messed it up. :-(