DoCmd.GotoRecord on a subform?

Hello - how do you reference a subform in the {ObjectName} arg of DoCmd.GoToRecord?

I have a global module for form operations where I do common things for Open, Current, add's, edit's, deletes, etc.  I pass the form as an object variable. This has worked well in the past, on stand-alone forms, but now I'm trying to re-work it to handle forms that are open as subforms. For my add routine, I go to the NewRecord:

DoCmd.GoToRecord acDataForm, frmThisForm.Name, acNewRec

It errors back with "(subform name) isn't open"

Thanks

mlagrangeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BitsqueezerCommented:
Hi,

the problem with subforms is that DoCmd.GoToRecord doesn't work with subforms in the syntax you wrote. The reason is that it always search the form name as a main form which can't be found as it is of course a subform.
But you can do the following method:

Forms("FormMainName").SubformName.SetFocus
DoCmd.GoToRecord acActiveDataObject, , acNewRec

Be sure that "SubformName" is the name of the subform control, not the included subform.

Cheers,

Christian

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mlagrangeAuthor Commented:
THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU!
I have been stumped on this for hours!
BitsqueezerCommented:
No problem, you're welcome...:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.