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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referrencing a subform or a subform's objects 2

Status
Not open for further replies.

TheInsider

Programmer
Jul 17, 2000
796
CA
Hi,
Real simple question: How do I referrence a subform or the objects in a subform that is open. One would expect that the form (being open) would be accessable through the forms collection ie. "Forms!MySubForm.MyTextBox" or even "Forms!MyParentForm.MySubForm.MyTextBox". I would like to referrence a list box, and various fields in the recordsource of the subform from a procedure, query, or parent form.
Thanks,
Rob Marriott
CCTC1
rob@career-connections.net [sig][/sig]
 
Ok, I figured out how to referrence the objects on the subform with... "Me.MySubForm.Form.MyObject"
but I still don't know how to referrence the current record's fields in the subform's recordsource. [sig][/sig]
 
Hi Rob,

try
get value
avariable = Me![SubformName].Form![FieldName]

or
set value
Me![SubformName].Form![FieldName] = avariable

this will refer to what ever the current record is in the subform ie if you went to a record in the subform then executed code in the main form it will retrive the field value on that record. you might want to use a temp variant and test this before assigning it to a specific var type.

HTh


[sig][/sig]
 
Hi,
Thanks for responding, unfortunately I cannot seem to get your method to work. The parent and child/sub forms are open and I have spelled the subform correctly, but Access still says that it can't find the "field" - which is actually my subform. I have tried many combinations and have tried "." instead of "!" and the other way around. I am really stumped. Any chance you could create a quick sample database and e-mail it to me? This could just be a form with a command button that when clicked displays a message box containing the value in a text box on the subform.
Thanks,
CCTC1
Rob Marriott
rob@career-connections.net [sig][/sig]
 
Sorry my dumb mistake. You had the right idea... the text box that I was trying to referrence on the subform had the default name of "fldFundName", I had forgotten to rename this. I use the Visual Basic prefixes, so I was expecting "txtFundName". Also, you have to referrence the subform object on the parent form, not the actual form. I had the subform object named with a different prefix than the subform itself - and thus was trying to referrence the form.
Thanks again,
CCTC1
Rob Marriott
rob@career-connections.net [sig][/sig]
 
Sorry to butt in on what seems a solved issue, but....

With regards to your changed/incorrect field name (so easily done), I thought you might want to hear of a similar problem I had trying to access the recordset on subform on a tabcontrol on a subform on a form. It was a nightmare trying to work it out....Not least because I had accidentally changed the control name of the subform (on its form) from its actual name. Needless to say the combination of not knowing the syntax AND having a control name difference had me going around in circles for sometime.

I now make doubley sure that the control name of a subform and its actual name are always the same (except where you intend display different forms in the same subform control...but thats another story)..... [sig][/sig]
 
Hi,
I'd like to thank both Robertd and KirkJewell for their responses. I think KirkJewell is correct, in that subform objects should be named the same as the form itself, to avoid any confusion. I think that this is a good rule of thumb. [sig]<p>Rob Marriott<br><a href=mailto:rob@career-connections.net>rob@career-connections.net</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top