From: alekm on
How do I do passing objects and names?


"Marshall Barton" wrote:

> That will work in most situations, but there is no guanantee
> that the active screen object is the form with the check
> box.
>
> You would be better off if you can find a way to use the
> FORM's ActiveControl property.
>
> If your common code is in a standard module, then passing
> the form object or name to the common routine would be
> better.
> --
> Marsh
> MVP [MS Access]
>
>
> alekm wrote:
> >I get it:
> >Screen.ActiveControl.value
> >
> >"alekm" wrote:
> >> let's say I'm writing a code and I'm in the middle of event procedure for
> >> check box. How do I check the current value of check box not reffering it by
> >> name? Is there any other way than reffering it by its name. I want same code
> >> to apply to several check boxes so I don't want to names fixed in code.
>
> .
>
From: Marshall Barton on
You can pass a form name in the function;s arguments:

Public Sub MySub(nm As String)
If Forms(nm).ActiveControl Then
'Checkbox is checked
Else
'Checkbox is not checked
End If
End Sub

Then call it with:
MySub Me.Name

Passing the form object would be like:

Public Sub MySub(frm As Form)
If frm.ActiveControl Then
'Checkbox is checked
Else
'Checkbox is not checked
End If
End Sub

Then call it with:
MySub Me
--
Marsh
MVP [MS Access]


alekm wrote:
>How do I do passing objects and names?
>
>
>"Marshall Barton" wrote:
>> That will work in most situations, but there is no guanantee
>> that the active screen object is the form with the check
>> box.
>>
>> You would be better off if you can find a way to use the
>> FORM's ActiveControl property.
>>
>> If your common code is in a standard module, then passing
>> the form object or name to the common routine would be
>> better.
>
>> alekm wrote:
>> >I get it:
>> >Screen.ActiveControl.value
>> >
>> >"alekm" wrote:
>> >> let's say I'm writing a code and I'm in the middle of event procedure for
>> >> check box. How do I check the current value of check box not reffering it by
>> >> name? Is there any other way than reffering it by its name. I want same code
>> >> to apply to several check boxes so I don't want to names fixed in code.