How to add a new record to subform from main form?

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

hi guys,

the subject line tell it all..
What is the code to add a new record to subform from the
main form?
The lines:

Me!frm_sub_ServiceAddresses.Form.NewRecord

DoCmd.GoToRecord acDataForm, Me!
frm_sub_ServiceAddresses.Form, acNewRec

do not work. Any suggestions?

Thank you.
 
first, make sure you're using the name of the subform control in the main
form. open the main form in design view, right click on the subform and
select Properties. click the Other tab and look at the Name property. use
that name in your code - in the main form - as follows:

With Me!MySubformControl.Form
DoCmd.RunCommand acCmdRecordsGoToNew
End With

hth
 
Hi Tina,

Unfortunately
this command just adds a new record to a main form's
recordsource.
What i need just add a new record to subform's
recordsource, with the slave field filled out
automatically from the master field of main form...

The problem is still there.
Thanks.
 
hmmm, i tested the solution, before posting, on A2003 in an A2k format db.
went to new record in the subform without a problem.
suggest you post more detail about when/where you're calling the code. also,
check your subform's AllowAdditions property, make sure it's set to Yes.
 
yes,
it adds a new record, but to main form.
Where i put the code:
on the button even click, button location - main form:
With Me!frm_sub_ServiceAddresses.Form
DoCmd.RunCommand acCmdRecordsGoToNew
End With

There are main form - frm_Customers;
and subform - control's name - frm_sub_ServiceAddresses.

The Allow Additions property is set to Yes.


Tina, when you click on the button when you tested
it..what happens?
does the fields in the main form become blank?- this is
what happens in my case - new record to the form is
added..
the fields in the subform also become
blank..uderstandable.

Thanks for taking time to answer my question.

Alex
 
when i click the button in my test form (in the main form) the subform jumps
to new (blank) record; the main form is not affected at all. i added a line
of code to set focus on the appropriate field in the subform, but that runs
*after* the new record code runs.
hopefully an MVP or some other smart person will solve this mystery for us.
<g>
 
Alex said:
Hi Tina,

Unfortunately
this command just adds a new record to a main form's
recordsource.
What i need just add a new record to subform's
recordsource, with the slave field filled out
automatically from the master field of main form...

The problem is still there.
Thanks.

Assuming the subform in question is only one level deep -- that is, it
is a child of a main form, not a child of a subform -- you should be
able to do it by setting the focus to the subform control, then telling
Access to go to a new record on the "active data object":

Me!frm_sub_ServiceAddresses.SetFocus
DoCmd.GoToRecord acActiveDataObject, ,acNewRec
 
Yes, it worked. Thanks.

-----Original Message-----


Assuming the subform in question is only one level deep - - that is, it
is a child of a main form, not a child of a subform -- you should be
able to do it by setting the focus to the subform control, then telling
Access to go to a new record on the "active data object":

Me!frm_sub_ServiceAddresses.SetFocus
DoCmd.GoToRecord acActiveDataObject, ,acNewRec

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
cool, another "trick" to put up my sleeve! :)


Dirk Goldgar said:
Assuming the subform in question is only one level deep -- that is, it
is a child of a main form, not a child of a subform -- you should be
able to do it by setting the focus to the subform control, then telling
Access to go to a new record on the "active data object":

Me!frm_sub_ServiceAddresses.SetFocus
DoCmd.GoToRecord acActiveDataObject, ,acNewRec

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top