[AccessD] A2003: Formatting a text Box

Foote, Chris Chris.Foote at uk.thalesgroup.com
Wed Feb 2 05:40:05 CST 2005


Hi Darren!

I'm not sure about A2003 or formatting in control source. But I've used the
following code in the "Current" event of a form to set the colour of a text
box control depending upon the contents of the control. This works in A97 &
A2k.

------------Code snippet start----------------

'=========================
' Code to set colour of txtLifeDate
' depending upon "age" of date
'==================
'
Dim sValAge As Date
Dim txtTest As Integer

If Not IsNull(txtLifeDate.Value) Then

txtTest = DateDiff("m", Me.txtLifeDate.Value, Now())

Select Case txtTest
Case 0 To 6
Me.txtLifeDate.ForeColor = 6723891 'Green

Case 6 To 12
Me.txtLifeDate.ForeColor = 39423 ' Orange

Case Else
Me.txtLifeDate.ForeColor = vbRed ' Red

End Select

Else

End If

------------Code snippet end----------------

Hope this helps!

Chris Foote

> -----Original Message-----
> From: Bryan Fitzpatrick [mailto:bryan.fitzpatrick at cyberone.com.au]
> Sent: Wednesday, February 02, 2005 9:47 AM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] A2003: Formatting a text Box
> 
> 
> Darren
> The FORMAT  propertyof a textbox allows some control of this. 
>  Check it 
> in the on-line Help.  I know that you can set up to four different 
> formats for a number field, but I'm not sure if it works for text.
> 
> HTH
> bryan
> 
> Darren DICK wrote:
> 
> >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