Passing a reference to a control on a subform to a function

vicissitude

Registered User.
Local time
Today, 16:57
Joined
Feb 28, 2010
Messages
92
I was wondering if someone could give me a hand with this one....

I have referenced a control on a form from a function in a module using this:
Forms(frm.Name).Controls(ctl.Name).Value

The function looks like this:
Function(frm as form, ctl as control)

The function call looks like this:
Call Function(me, me.ctl)

This all works fine but i cannot work out how to do the same thing except referencing the control in a subform, i.e. what do you pass to the function and how do you reference it in the function?

I have tried everything i can think of, stuff like....

Forms(frmParent.name).Forms(frmSubform.name).Controls(ctl.name).value

and passing it like this...

Call Function(me.parent, me, me.ctl)
Function(frmParent as form, frmSubform as form, ctl as control)

but no luck.

Thanks in advance.
 
Presumably the subform in question is a child to your main form in which the Call staement is done? Also the new call you want to make is from that subform code? If so, the call should look like this:
Code:
Call Function(Me, Me.Parent.ctl)
Is ctl the name of a control on your main form or is it a variable which is set to point at one of any controls on the form?
 
Yes i have a form and subform (datasheet style).

Each row in the subform datasheet has a checkbox which is set yes by default. If this is clicked to 'unchecked' then the user is alerted to confirm choice via messagebox.

So yes the code starts in the subform, and calls the function in the module from there but i take it you have to include the parent of the subform in the reference?

So the frmParent is the main form
the frmSubform is the subform of the parent
the ctl is the checkbox on the subform (datsheet style)
 
If I understand you correctly, the call should be
Code:
Call Function(Me, Me.ctl)
when placed in the subform because the form in which the code is located (i.e. the subform) is the 'Me' in question and the 'ctl' belongs to it. Begs the question why you need the form Id at all - just pass the control id to the function? so
Code:
Function(ctl as control)
and
Code:
Call Function(me.ctl)
 
Nice one!

Thats it! For some reason i had it in my head that you had to always do the whole reference thing from the main form down to the control no matter where you referenced it from.

So you can just pass the control and nothing else, excellent.

Thanks!
 

Users who are viewing this thread

Back
Top Bottom