Results 1 to 2 of 2

Thread: Change Label color based on caption in Label with VBA code
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jun 2016
    Posts
    125
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Change Label color based on caption in Label with VBA code

    Hello,

    I have a userform with a label "txtRest" using the following code to get the total amount. (this code is in subroutine "txtTotal_Change")
    Code:
    Me.txtRest = (IIf(Format(Me.txtTotal, "#,##0") = "", 0, (Format(Me.txtTotal, "#,##0"))) + 0) - (IIf(Format(Me.txtPaid, "#,##0") = "", 0, (Format(Me.txtPaid, "#,##0"))) + 0)

    What I'm looking for is change the Back color of this label to "Yellow" in case the amount is greater than Zero
    In case "Zero" change it to White

    Please help me with this and in which sub I should add the code?

    Another favor if possible, Is there any short way for the above code, since I'm using it with many textboxes

  2. #2
    Board Regular gallen's Avatar
    Join Date
    Jun 2011
    Location
    Manchester UK
    Posts
    1,899
    Post Thanks / Like
    Mentioned
    21 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Change Label color based on caption in Label with VBA code

    Code:
    Me.txtRest.BackColor = IIf(Val(Me.txtRest.Value) > 0, vbYellow, vbWhite)

    - forum use guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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