Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2010
    Posts
    5

    Unanswered: Pass the control that triggered an event to a function?

    Hey all,

    I was wondering if it was possible to pass the control itself as a function parameter to the function that one of it's event procedures is set to.

    Example: (this is what I had imagined)

    set the OnClick event property of a command button named "btnTest" on a form to "=testFunction([Control])"

    where the testFunction function is defined as:

    Public Function testFunction(ctl as Control)

    MsgBox ctl.Name

    End Function

    Therefore, clicking on the command button would give the user a message box containing the message "btnTest"

    I know that this is possible with the FORM that the control is on. For example, if I have a form called "frmTest" with a command button called "btnTest" whose its OnClick event property set to "=testFunction([Form])" and the function testFunction is defined as

    Public Function testFunction(frm as Form)

    MsgBox frm.Name

    End Function

    In this case, the user will receive a message box containing the message "frmTest"...And it works!

    How can I make this work for the control ITSELF? I don't want to have to type in the control's name every time I repetitively use this function, I just want the function to know which control called it.

    Is this possible?

    Thanks in advance

  2. #2
    Join Date
    May 2010
    Posts
    601
    Quote Originally Posted by cypage View Post
    Hey all,

    I was wondering if it was possible to pass the control itself as a function parameter to the function that one of it's event procedures is set to.

    Example: (this is what I had imagined)

    set the OnClick event property of a command button named "btnTest" on a form to "=testFunction([Control])"

    where the testFunction function is defined as:

    Public Function testFunction(ctl as Control)

    MsgBox ctl.Name

    End Function

    Therefore, clicking on the command button would give the user a message box containing the message "btnTest"

    I know that this is possible with the FORM that the control is on. For example, if I have a form called "frmTest" with a command button called "btnTest" whose its OnClick event property set to "=testFunction([Form])" and the function testFunction is defined as

    Public Function testFunction(frm as Form)

    MsgBox frm.Name

    End Function

    In this case, the user will receive a message box containing the message "frmTest"...And it works!

    How can I make this work for the control ITSELF? I don't want to have to type in the control's name every time I repetitively use this function, I just want the function to know which control called it.

    Is this possible?

    Thanks in advance
    Try:

    Code:
    =testFunction(Screen.ActiveControl)
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  3. #3
    Join Date
    May 2010
    Posts
    601
    I see you got the same answer HERE
    Boyd Trimmell aka HiTechCoach HiTechCoach.com (free access stuff)
    Microsoft MVP - Access Expert
    BPM/Accounting Systems/Inventory Control/CRM
    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  4. #4
    Join Date
    Jul 2010
    Posts
    5
    Thanks again,

    I responded HERE

  5. #5
    Join Date
    Jul 2010
    Posts
    5
    Because of a reminder that I have received from another user, I am updating this post to let everyone know that this is actually a cross-post. The post on the main forum is:

    Pass the control that triggered an event to a function? - UtterAccess Discussion Forums

    and the other side post is:

    Pass the control that triggered an event to a function?

    Thanks again in advance for any help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •