Setting subform to new record

jgc31

Registered User.
Local time
Today, 12:14
Joined
Dec 4, 2004
Messages
78
There's probably an obvious answer to this but I can't spot it.

I have a form with a sub form the data in the sub form is from a table at the many end of a one to many relationship with the table upon which the main form is based. When the form opens I want the sub form to go to a new record but to have the ability to click through the other records using the nav buttons. Pretty straight foward when opening the form using the onLoad event of the sub form do "DoCmd.GoToRecord , , acNewRec" .

However if I change the record of the main form I want the sub form to again default to a new record . Both options I have tried give an error. Using the onCurrent event of the main form with either

"DoCmd.SelectObject acForm, "sfrmEnterContactDetails", no
DoCmd.GoToRecord , , acNewRec"

or

"DoCmd.GoToRecord acDataForm, "sfrmEnterContactDetails", acNewRec"

gives an error the object "sfrmEnterContactDetails" isn't open.

Any ideas
 
SOunds like the master and child fields that link the subform to the mainform is not correct. Check out the properties of the subform to make sure the master/child fields are correct.


Normally if the relationship and the subform is linked correctly it should default to a new record when adding a new record to the main form, or have I misunderstood?

Andy
 
try refreshing the form

me.form.refresh
 
@ spacepro the fields on the main form are locked as the form is designed to enter data on the subform the data on the the main form is for info only however as a test I did hit the add new record button on the main form and the subform does indeed go to a new record

@ liv tried this but no difference
 
jgc31,

Bare with me , I have touched access for a while but I don't think you can use docmd.gotorecord,,acnewrec to do what you want.

When the form goes to a new record the nav buttons will not show you the other records in the subform which relates to the one side of the relationship, it sets the condition of the form to New records only.

I am guessing that you would have to create your own nav buttons and using code to control what you want to do, probably using 2 queries to control the recordsource of the subform.

Maybe others will have better suggestions or clarification of the above!

Hope this helps and Good luck!

Andy
 
Try
Code:
SubForm.SetFocus
DoCmd.GoToRecord , , acNewRec

SubForm is the name of your Subform-Object.
After adding the new record, your should set focus back to the element, that normally would have the focus.
 

Users who are viewing this thread

Back
Top Bottom