Results 1 to 2 of 2
  1. #1
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74

    VBA to change the greatest value textbox ForeColor (and label) to red.

    I'm creating a summary that uses Dcount() to count the number of records that meet certain criteria (# of projects in a state, for example). Once these values are calculated I'd like to change the ForeColor of the highest value to Red so that it sticks out. I can loop through the control elements on the form, but I'm trying to figure out how to change the fore color.



    I have three textboxes:
    tboxRegion2
    tboxRegion3
    tboxRegion4

    This code loops through all of the textboxes on the form and finds the one with the highest value.
    Code:
        Dim c As Control    Dim txt As TextBox
        Dim high As Integer
        Dim value As Integer
        Dim tbox As String
        
        high = 0
        
        For Each c In Me.Controls
            If TypeOf c Is TextBox Then
                Debug.Print c
                value = c
                If value > high Then
                    high = value
                    tbox = c.Name
                End If
            End If
        Next c

    This code changes the ForeColor property to red:
    Code:
    Me.tboxRegion4.ForeColor = RGB(255, 0, 0)
    What I need to do is combine the two code blocks by building the Me. statement using the variable tbox. For example:
    Code:
    "Me." & tbox & ".ForeColor = RGB(255,0,0)"
    I need Access to evaluate this statement rather than treat it as a string.

    Recommendations?

  2. #2
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    Answered my own question with further googling...
    Where tbox is a variable storing the name of the textbox control:

    Code:
    Me.Controls(tbox).ForeColor = RGB(255,0,0)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 01-16-2013, 12:12 PM
  2. Change size of Label
    By amerifax in forum Access
    Replies: 1
    Last Post: 10-17-2012, 06:18 PM
  3. Replies: 10
    Last Post: 03-06-2012, 11:48 AM
  4. Textbox/label Visible
    By prawln in forum Programming
    Replies: 6
    Last Post: 05-20-2011, 01:57 PM
  5. Change of label size
    By Zoroxeus in forum Programming
    Replies: 0
    Last Post: 06-11-2007, 08:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums