[AccessD] A2003: Formatting a text Box

Gustav Brock Gustav at cactus.dk
Wed Feb 2 03:27:19 CST 2005


Hi Darren

Not that I know of, but you can create a small function which does
this:

Private Function SetTest(ByVal varValue As Variant) As Variant

  Dim lngForeColor  As Long
  
  With Me!txtTest
    ' Specify default ForeColor value.
    lngForeColor = vbBlack
    If IsNumeric(varValue) Then
      If Val(varValue) > 500 Then
        lngForeColor = vbBlue
      Else
        lngForeColor = vbRed
      End If
    End If
    ' Make other tests.
    ' ...
    ' Set ForeColor
    .ForeColor = lngForeColor
  End With
  
  SetTest = varValue
  
End Function

Then set the ControlSource of textbox txtTest to:

=SetTest([txtInput])

Now txtTest will show the value in txtInput and adjust forecolor.

/gustav

>>> d.dick at uws.edu.au 02-02-2005 05:30:55 >>>
Hello all
I want the text in a text box to be blue or red depending on
conditions

Can it be done in the control source of the Control?
I know it can be done via Conditional Formatting or in code
Just wanna know if it can be done in the control source

EG (pseudo code)

=IIf([SomeValue]=-1,Format([SomeControl].ForeColor,"vbred","vbblue"))

Many thanks

Darren




More information about the AccessD mailing list