Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / December 2005

Tip: Looking for answers? Try searching our database.

Get control name in click event procedure

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Olive Music - 05 Dec 2005 17:55 GMT
I have a form with two dozen command buttons on it that will all perform a
similar routine. Each of the buttons click events will have its own
subroutine in the VBA code, and all the subroutines will call the same
function. To have that function perform logic specific to a given button, I'd
have to pass the name of the button to the function. I'd rather use a
variable, so that for each button click event subroutine that I create, all I
have to do is copy and paste the statement from another button's click event
without having to subsequently change the function argument to be the
button's name. (I know that sounds lazy, but two dozen is a lot, and anyway
I'm curious if it can be done.) An alternative would be to somehow use the
subroutine's name as the value (since the name of a command button's click
event contains the button's name). But I haven't found a way to do that
either.
Douglas J Steele - 05 Dec 2005 18:11 GMT
Screen.ActiveControl.Name

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> I have a form with two dozen command buttons on it that will all perform a
> similar routine. Each of the buttons click events will have its own
[quoted text clipped - 9 lines]
> event contains the button's name). But I haven't found a way to do that
> either.
Marshall Barton - 05 Dec 2005 19:43 GMT
>I have a form with two dozen command buttons on it that will all perform a
>similar routine. Each of the buttons click events will have its own
[quoted text clipped - 9 lines]
>event contains the button's name). But I haven't found a way to do that
>either.

Me.ActiveControl.Name

Signature

Marsh
MVP [MS Access]

Marshall Barton - 05 Dec 2005 19:51 GMT
>>I have a form with two dozen command buttons on it that will all perform a
>>similar routine. Each of the buttons click events will have its own
[quoted text clipped - 11 lines]
>
>Me.ActiveControl.Name

Whoops, wasn't done typing.

Me.ActiveControl.Name is more specific than the
Screen.ActiveControl.Name

I really wanted to point out that you can set the OnClick
property to call your general function.  Use =functionname()
instead of [Event Procedure] to save you from having a
separate function for each button that doesn't do anything
beyond calling the general procedure.

Signature

Marsh
MVP [MS Access]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.