NoChance
NoChance

Reputation: 5752

MS-Access 2007 - How to programatically access sub form columns data on click event

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!

Upvotes: 1

Views: 196

Answers (2)

marlan
marlan

Reputation: 1485

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.

Upvotes: 1

Gustav
Gustav

Reputation: 55806

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.

Upvotes: 1

Related Questions