add record to subform

J

jacks

I have a main form with a sub form in continuous view. I
created a button on the main form and would like to add a
new record on the sub form when clicked. How would I do
this?
 
A

Allen Browne

To create a new record in code and then display it in the subform, AddNew to
the form's RecordsetClone:

Dim frm As Form
Set frm. = Me.[NameOfYourSubformHere].Form
With frm.RecordsetClone
.AddNew
![SomeField] = "Some text to go here"
![AnotherField] = "whatever it should read"
.Update
frm.Bookmark = .LastModified
End With
Set frm = Nothing


If you don't want the new record saved until the user has entered more
stuff, you would need to set focus to the subform, set focus to a control
within the subform, RunCommand acCmdRecordsGotoNew, and then assign a value
to one or more of the controls.
 

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