How to pass control in the onclick event of a button

tonez90

Registered User.
Local time
Today, 21:47
Joined
Sep 18, 2008
Messages
42
Hi,

I wish to send a control name or tag via the onclick event. I have posted an alpha filter example (see http://www.access-programmers.co.uk/forums/showthread.php?t=190087)

Essentially I pass the litteral value of the control (i.e. A) to a filter. What I want to do is simply pass the control as a standard control (i.e. Control). I have seen you can send the Form via the form statement in the Onclsick event so how do I send the Control. Essentially I want to standardise the passing parameters instead of having to have A, B, C etc)

Any Ideas

Cheers in advance
 
Controls is a collection of the Forms collection.

Forms(Name_of_Form).Controls(Name_Of_Control)

An item in the Controls collection is a Control.
 
Thanks but what I am after is a simpler approach to standardise the calling of a function. The name of the control is what I use to get the tage of that control in the function. I simply what to develop a statement such as =FSetFilter(control) instead of =FSetFilter([A]) for a button control named A and then do =FSetFileter() for the button control named B and so on to Z.

Essentially is there a way top pass the control via an onclick statement like =FSetFilter([Control]) for all the buttons instead of individual naming????
 
You cannot amend (i.e. add to or remove) the paramters of a control's event signature.

This is what Functions are for. You can call a function on the On Click event that will contain the additional parameters.

That equal sign you put there indicates a Control Source?
 
You can refer to the button that was just clicked by using:
Me.ActiveControl.Name

of in your case:

=FSetFilter(Me.ActiveControl.Name)

I am not exactly sure just what you are trying to do here, but I just wanted to answer the question you asked.
 
Okay I finally figured it out. In case anyone is interested.

=fSetFilter([ActiveControl])

To send control use [ActiveControl], for a form use [Form]

In the function refer to it as
Public Function fSetFilter(ctl As Control)
If wanted to pass form and control then
=fSetFilter([Form],[ActiveControl]) and then
Public Function fSetFilter(frm as form, ctl As Control)

then you can use ctl.name and ctl.tag etc

Thanks everyone for the guidance and help
 
Okay I finally figured it out. In case anyone is interested.

=fSetFilter([ActiveControl])

To send control use [ActiveControl], for a form use [Form]

In the function refer to it as
Public Function fSetFilter(ctl As Control)
If wanted to pass form and control then
=fSetFilter([Form],[ActiveControl]) and then
Public Function fSetFilter(frm as form, ctl As Control)

then you can use ctl.name and ctl.tag etc

Thanks everyone for the guidance and help
Glad you got that sorted. That was what I was hinting to you in post #2 ;)
 

Users who are viewing this thread

Back
Top Bottom