Passing a Control as a Sub Parameter to trap the onEnter/onExit Event

  • Dear Experts


    In order to make my controls to look nice, I'd like to change the border color when the user enters and exits a control.
    I've created the following two subs

    Code
    Sub GetEnterListbox(ByRef lst As MSForms.ListBox)
    lst.BorderColor = vbRed
    End Sub
    
    
    
    
    Sub GetExitListbox(ByRef lst As MSForms.ListBox)
    lst.BorderColor = vbBlack
    End Sub


    And I put the code into the onEnter/onExit of the listbox.


    I'd have to create subs for each type of controls.


    Is there a way to create a neater sub?
    For example, a sub that just takes any object and then checks for the type of object? Like:




    Or is there a better way to create a sub that traps the onEnter/onExit event automatically, without me having to call a sub each time?
    Some userforms have two and more listboxes and textboxes.


    Thanks for your help.


    Maria

  • Re: Passing a Control as a Sub Parameter to trap the onEnter/onExit Event


    This should help you:


    _______________________________________________
    There are 10 types of people in the world. Those that understand Binary and those that dont. :P


    Why are Halloween and Christmas the same? Because Oct 31 = Dec 25... ;)

    _______________________________________________

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!