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

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?)
 
W

Wayne Morgan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top