Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing control properties depending on field values

Status
Not open for further replies.

NigelR

Technical User
Jan 25, 2002
16
0
0
GB
Hi,
I'd like to change the backcolor property of a textbox in a report depending on the value of the field (currently "T", "P" or null).
Has anyone managed to change a control's properties in a report like this?
Thanks in advance.
 
If using A2k or later then lookup Conditional Formatting under Help.
 
You might be able to do something *like* the following in the Detail_Format or other sections Format event handlers, or in other event handlers. Look at the list of events for Reports in Help :) .

Related info, but regarding Forms:
****************
Form_OnCurrent event (handler)

Build code for those events that checks the value of controls and sets formatting for the fields appropriately.

Code:
    Private Sub Form_Current()

        'You could do this for lots of controls :)
        Select Case Me.txtTPNULL.Value
        Case "T"
            Me.txtTPNULL.BackColor = myconstGREEN
        Case "P"
            Me.txtTPNULL.BackColor = myconstRED
        Case Is Null
            Me.txtTPNULL.BackColor = myconstGREY
        End Select

    End Sub

Read the help for when these events fire. Realise that they will fire each time a different record is loaded, so if a user is scrolling through lots of records quickly (say by holding down the record navigation forward button), the event will be firing repeatedly. If it isn't heavy-duty code, this shouldn't be a huge problem. But be aware of it.
****************
 
Someone else asked the same question as you; here's the answer they got from pdldavis, copied w/o checking with pdldavis. I hope he/she doesn't mind helping someone else, too :) .

pdldavis (TechnicalUser) Mar 25, 2002
Hi, assuming you have a text box in the detail section of your report named DaysToShip, you could go to the reports Detail Format section in VB and place a statement in the the Private Sub:

if ([ShippedDate]-[ReceivedDate]>10 Then
me!daystoship.backcolor = 10092543 Else 'Light Yellow
me!daystoship.backcolor = 16777215) 'White

This would change the back color of the DaysToShip Text Box

Hope that helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top