Results 1 to 4 of 4

Thread: [RESOLVED] How to identify the control that was clicked?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    7

    Resolved [RESOLVED] How to identify the control that was clicked?

    Could anyone please tell me how my program could identify the control that is clicked? In other words, lets say I have 20 controls on the form(no arrays, all different control types). And in the click event for any given control, I want to be able to call a function and pass to that function the name of the control that was clicked. How would I code that? Thanks in advance. Ron E.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to identify the control that was clicked?

    Me.ActiveControl.Name
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to identify the control that was clicked?

    Welcome to the forums.

    Any clickable control has a click event, pass itself to the function
    Code:
    Private Sub Image1_Click()
         ProcessClickedControl Image1
    End Sub
    
    Private Sub ProcessClickedControl(theControl As Control)
         MsgBox theControl.Name & " was just clicked"
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2009
    Posts
    7

    Resolved Re: How to identify the control that was clicked?

    Thanks, Keith. I just could not believe it was that simple. Ron

Posting Permissions

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



Click Here to Expand Forum to Full Width