Formatting Controls' Font (1 Viewer)

sportsguy

Finance wiz, Access hack
Local time
Today, 13:03
Joined
Dec 28, 2004
Messages
358
I am trying to color all controls which have a value of 0 as grey, to be less obvious to the observant's eye, and the remaining controls with the values greater than ZERO as black. . .

ctlDetail.Value = 0 doesn't work, what am i missing??

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

    ' Change Color to Grey for all controls which equal ZERO

    For Each CtlDetail In Me.Detail.Controls
        If CtlDetail.Value = 0 Then
            With CtlDetail
                .ForeColor = vbGrey
                .FontBold = False
            End With
        Else
            With CtlDetail
                .ForeColor = vbBlack
                .FontBold = False
            End With
        End If
    Next

End Sub

Thanks in advance
sportsguy
 

Isskint

Slowly Developing
Local time
Today, 18:03
Joined
Apr 25, 2012
Messages
1,302
Conditional formatting would be an easier way to achieve this.:)
 

ChrisO

Registered User.
Local time
Tomorrow, 03:03
Joined
Apr 30, 2003
Messages
3,202
Could it be that you don’t have Option Explicit?

CtlDetail is not declared nor is vbGrey.

vbGrey is not a colour constant, at least not in Access 2003, and so would be created as a Variant and initialized to Empty. When used as a numerical value that Empty is typecast to a number. The number defaults to 0 which is equal to vbBlack.


Edit
You may also need to be particular about which controls you are referring too.
If CtlDetail.ControlType = acTextBox Then


Chris.
 
Last edited:

sportsguy

Finance wiz, Access hack
Local time
Today, 13:03
Joined
Dec 28, 2004
Messages
358
Answer is:

Code:
Option Compare Database
Option Explicit


Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim ctlBox As Control

'  Change color to Grey for all prices which equal Zero

For Each ctlBox In Me.Detail.Controls
    If ctlBox.ControlType = acTextBox Then

        If ctlBox.Value = 0 Then
            ctlBox.ForeColor = RGB(213, 213, 213)
            ctlBox.FontBold = False
        Else
            ctlBox.ForeColor = vbBlack
            ctlBox.FontBold = True
        End If
    End If
Next

  
        
End Sub
 

Users who are viewing this thread

Top Bottom