Create an Enter/Exit code for All Objects on a Userform

  • I have many userforms with many objects on them (listboxes, textboxes etc).


    In order for the user to 'see' where the courser is, I'd like to change the background color or border color of the current object.


    Is it possible to create a code which handles the Enter/Exit event for all objects?


    Maria

  • Re: Create an Enter/Exit code for All Objects on a Userform


    Yes.. Userform1.textbox1.setfocus will move cursor, Userform1.textbox1.BackColor = &H8000000D would set backcolor to Highlight Blue.

  • Re: Create an Enter/Exit code for All Objects on a Userform


    Right... now lets assume that I have


    5 textboxes
    2 listboxes
    1 combobox


    I could set the backcolor of the object to blue on Exit and set it back to a default color on Exit.
    In my example, I would have to create 16 additional procedures (2 for each object x 8 objects).
    Needless to say that this is tedious and hard to manage.


    Is it possible to create 1 or 2 procedures per userform that would handle this?

  • Re: Create an Enter/Exit code for All Objects on a Userform


    Read this link, It should help point you in the right direction http://www.ozgrid.com/forum/showthread.php?t=172689


    I typically use a sub at the bottom of my code that I can copy and paste to all the events, then I just gosub it.


    Keep in mind that application.enableevents = false does not work in userforms if you have some reason to halt a change event. For that you need to declare a public boolean variable, then at the top of each each code test if true then exit sub.


    That comes in handy if looping through all your objects in the userform.


    Example, In my userform, I have a Reset button, I then declare the public boolean to true
    Then I loop through removing any input data and reseting any formating back to a default value.


    Here is a link on how to loop through the object. http://www.ozgrid.com/VBA/control-loop.htm


    Hope that helps..

Participate now!

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