Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2003
    Harrow, UK

    Unanswered: Counting how many controls are red

    I have a form which acts as an overall process status indicator. There are sixty textboxes which change colour every 5 minutes dependent on various things. Each can either be Red, Amber or Green. I want to have a counter that can tell me how many are currently Red (or Green etc.).

    The attribute that changes is BackColor.
    Any ideas?
    Thank you,

  2. #2
    Join Date
    Jul 2003
    What you need to do is loop thru all the controls in your form, and check the background color. Maybe do this in the forms On Timer event?

    put 3 controls on the form to contain the counter values (txtRed,txtlAmber,txtGreen)

    you'll have to adjust the numbers in the constants to the colors you are actually using.

    const clrRed as Long = 255
    const clrAmber as Long = 65535
    const clrGreen as Long = 65280
    const clrGreen
    Dim ctl as Control
    Dim frm as Form
    Dim intRed as Integer, intGreen as Integer, intAmber as Integer
    Set frm = Forms("YourFormName")
    for each ctl in frm.Controls
    *some controls don't have a backcolor property, I assume you want to check only labels and text boxes. See help for ControlType property for other constants
    If ctl.Controltype = acTextBox or ctl.ControlType = acLabel then
    Select Case ctl.BackColor
    Case clrRed
    intRed = intRed + 1
    Case clrAmber
    intAmber = intAmber + 1
    Case clrGreen
    intGreen = intGreen + 1
    End case
    End if
    txtRed.Value = intRed
    txtGreen.Value = intGreen
    txtAmber.Value = intAmber
    Inspiration Through Fermentation

Posting Permissions

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