1

I have an unbound form that includes a subform. The subform is unbound and gets populated when the user clicks on a push button on the main form.

I want to be able to grammatically handle the click even on the sub form and get the data in a specific column. How can I do that? The same thing one would do with VB.NET/C#.NET if you know what I mean.

When I use the properties tab of the subform, I get an expression builder. That does not get me into a sub/function/form or module VBA code editor.

Any help is appreciated.

Edit - Something that worked! Thanks for the help I got from the answers below. One way to refer to column in a selected row in a subform is by using this expression:

Me!ChildFormName.Form!ColumnNameInSubForm

EX:

ME!Sales.Form!SalesmanID

Additional Reference here...

A problem with this approach is that the available events On Enter and On Exit don't behave like "click" event does. One needs to focus out of the sub form (by clicking on another control) for either to be triggered!

2 Answers 2

1

Look again. The Properties' sheet has a tab, Events. Select any event and select "Event Procedure" from the dropdown and click the ellipsis - that opens the code editor.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your help. Yes there is text [event procedure]. When I type any name there and go to the code, I don't get an event handler created in the code. What do you suggest I do so that I can get the event handler created in the code? (like C#/VB)? Thx.
You don't type in any text. You click the ellipsis and reach the event handler whery you type in. The name of the subfunction follows the name of the control.
Yes, you are correct. I got the handler created :) - How can I access the selected row data? Sorry to ask so many questions of you!
That is Me!SomeControl.Value. But it sounds like you really need to look up a tutorial to get some firm ground. Lots out there for the browsing.
1

Refer to sub-form control form main-form event handler (VBA Sub):

Me!Subform1.Form!ControlName

Me is self reference to the main-form, Subform1 is the control containing the sub-form, Form is a reference to the sub-form, and ControlName is a reference to the field on the sub-form. ! is a short way to refer to a control in a form's contrls collection.
A longer way to write the above would be: Me.contrls("Subform1").Form.Contrls("ControlName")

Refer to a main-form control form a sub-form event handler (VBA Sub):

Me.Parent!ControlName

Me is self reference to the sub-form, Parent is a reference to the main-form, and ControlName is a reference to the field on the main-form.
A longer way to write the above would be: Me.Parent.Contrls("ControlName")

Please see more on the topic in this link.

3 Comments

Thanks for your help. I need to able to access the selected row columns from the subform. When I try ME!SubformName.RecordSource I get "Object does not support property"! Also, using ME!SubformName.Value does not work since Value is not a property.
Try ME!SubformName.Form.RecordSource. ME!SubformName is a control on main-form, ME!SubformName.Form is a reference to the actual sub-form.
Great! it's not an other way, it's exactly this way: Me!Subform1.Form!ControlName. Subform1 is what you called ChildFormName, and ControlName is what you have called ColumnNameInSubForm ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.