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

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.
 
T

tina

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
 
A

Alex

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.
 
T

tina

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.
 
A

Alex

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
 
T

tina

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>
 
D

Dirk Goldgar

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
 
A

Alex

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)


.
 
T

tina

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)
 

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