Using docmd.GoToRecord to add a new record to a subform

  • Thread starter Thread starter John Baker
  • Start date Start date
J

John Baker

I would like to be able to add a button to a form which has code behind it
to add a new record to a subform. I will then be programmatically placing
data into the fields of the new record on the subform.

My problem is, how do I put a new record into the subform. I have been
trying to use
docmd.GoToRecord acform, "MySubFormname", acNewRecord

I also tried "forms!myForm!SubformName!subformcontrol.form.MySubformName"
as the form name, but in each case I get a type mismatch.

How can I use the docmd.GoToRecord to add a new record to a subform? (or is
there a better way?)
 
Try

Me.SubformControlName.Form.Recordset.AddNew

The SubformControlName is the name of the control that holds the subform,
not the name of the subform itself. To get this name, open the main form in
design view and open the Properties sheet. Click the subform ONE time. The
properties sheet should show the name of the subform control. If you click
the subform a second time, you'll be in the subform and the Properties sheet
will show the name of the subform, not the control holding it.
 
Back
Top