Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference subform of main form from separate pop-up?

Status
Not open for further replies.

lorirobn

MIS
Mar 15, 2005
450
US
Hi,

I have a main form, with a subform. I had a list box on the main form, from which you could select items, that would then in turn populate the subform. It worked great. But then... I decided to put the list box on a pop-up instead. Now my "DoCmd.GoToRecord , , acNewRec" statement is not working correctly, and an existing row gets overlaid on the subform instead of it going to a new line. I believe I am not referencing the subform correctly from my pop-up form.

My code, in the double-click event of the list on the pop-up, is as follows: (I changed form names for simplicity).
Code:
  Forms!frmMain!fsubSub.SetFocus
  DoCmd.GoToRecord , , acNewRec
I have tried many iterations, including "DoCmd.GoToRecord acDataForm, "Forms!frmMain!frmSubForm", acNewRec". Sometimes I get an error that the subform is not open, even though it is.
Any suggestions?
Thanks in advance.
 
How about:

[tt]Forms!frmMain.SetFocus
DoCmd.GoToControl "fsubSub"
DoCmd.GoToRecord , , acNewRec[/tt]
 
lorirobn,

Remember when accessing the subform you have to reference the form it contains

Code:
Forms!frmMain!fsubSub.[red]Form[/red].SetFocus
  DoCmd.GoToRecord , , acNewRec
 
I used Remou's suggestion and it works, thanks (I believe you helped me with the list box on the original form as well!).

Stix, I'm not sure what you mean by:
"you have to reference the form it contains". My subform doesn't contain a form, so not sure what you meant?

Thanks for the responses and the help!
Lori
 
lorirobn,
The sub form, fsubSub, on your main form is just a control that holds the form. You have to use the additional property "form" to access the items on the form, that's why I put in red. Remou's stuff was right, if you want to pull values or access values from a subform you have to use the additional "form" property. Just a good thing to know.
 
And if I may add, incase it was taken for granted,
Remou's code was succesful, amongst other reasons, was because he followed the hierarchy in referencing controls.

Regardless of where the focus is, you always start at the
top (main form), even if you already have focus, on a control, within the subform.

Nice & succinct Remou, I had a tendancy to use this;

Forms!frmMain.SetFocus
Forms!frmMain!fsubSub.Form.SetFocus
DoCmd.GoToRecord , , acNewRec

...not anymore!
 
It's all really good to know - thank you, all of you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top