+ Reply to Thread
Results 1 to 5 of 5

Change TextBox BackColor

Hybrid View

bdb1974 Change TextBox BackColor 06-28-2010, 04:39 PM
Leith Ross Re: Change TextBox BackColor 06-28-2010, 05:07 PM
bdb1974 Re: Change TextBox BackColor 06-28-2010, 06:04 PM
Leith Ross Re: Change TextBox BackColor 06-28-2010, 06:13 PM
bdb1974 Re: Change TextBox BackColor 06-29-2010, 05:07 PM
  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Change TextBox BackColor

    Hi all,



    I'm trying to change the back color on a textbox.

    example for 1 textbox entry among others that I will be conditionally changing the back color.
    Private Sub UserForm_Initialize()
    
    Dim  lngYellow As Long, lngWhite As Long
     lngYellow = RGB(252, 248, 61)
    lngWhite = RGB(255, 255, 255)
    
    With Me.TextBox1
    .BackColor = lngWhite
     End With
    
    If .TextBox1.Value = "" Then Me.TextBox1.BackColor = lngYellow
    End SUB
    Any help to fix this is appreciated.
    FYI:
    I don't know how, but during the process of trying this, I've changed the textbox1 back color to yellow.
    Everything that I've tried to set it back to white has failed.
    BDB
    Last edited by bdb1974; 06-29-2010 at 05:08 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Change TextBox BackColor

    Hello BDB,

    You only need to set the back color to yellow when the UserForm is initialized because it will come white by default. To change the color based on the contents of the TextBox, you need to add code to Change event. The code is below.
    Private Sub TextBox1_Change()
    
        Dim lngYellow As Long, lngWhite As Long
      
        lngYellow = RGB(252, 248, 61)
        lngWhite = RGB(255, 255, 255)
    
        TextBox1.BackColor = lngWhite
    
        If TextBox1.Value = "" Then TextBox1.BackColor = lngYellow
    
    End Sub
    
    Private Sub UserForm_Initialize()
    
        TextBox1.BackColor = RGB(252, 248, 61)
      
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Change TextBox BackColor

    Leith,

    I'm not sure what's going on. But it's not quite working yet with the color change. I will play around with this more tomorrow and report whether or not I've got it to run correctly.

    Thanks for you help.

    BDB

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Change TextBox BackColor

    Hello BDB,

    If you still have problems tomorrow, you should post the workbook. There may be some other factors affecting the TextBox.

  5. #5
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Change TextBox BackColor

    Leith,

    I figured out what the problem was.

    I had the routine event set run on "Initialization"

    Changing this to "activate" seemed to do the trick.

    Thanks again Leith for you assistance.


    BDB

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1