How to pass control in the onclick event of a button (1 Viewer)

tonez90

Registered User.
Local time
Today, 17:09
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
 

vbaInet

AWF VIP
Local time
Today, 08:39
Joined
Jan 22, 2010
Messages
26,374
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.
 

tonez90

Registered User.
Local time
Today, 17:09
Joined
Sep 18, 2008
Messages
42
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????
 

vbaInet

AWF VIP
Local time
Today, 08:39
Joined
Jan 22, 2010
Messages
26,374
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?
 

Mr. B

"Doctor Access"
Local time
Today, 02:39
Joined
May 20, 2009
Messages
1,932
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.
 

tonez90

Registered User.
Local time
Today, 17:09
Joined
Sep 18, 2008
Messages
42
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
 

vbaInet

AWF VIP
Local time
Today, 08:39
Joined
Jan 22, 2010
Messages
26,374
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

Top Bottom