Forecolor on or off (1 Viewer)

Lgvalencia

New member
Local time
Today, 07:53
Joined
Mar 8, 2023
Messages
10
I have a form and when the CDRL Type is Approval then I want it to show items in RED. When the CDRL Type is Non-Approval etc. then it would be black. It stopped working and I am not sure why. If anyone can point out why it doesn't turn RED it would be helpful.

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


    If Me![Expr3] = 1 Then
       ' Me![Part Number Label].Visible = True
        Me![Item Number Label].Visible = True
        Me![Comments Label].Visible = True
    Else
      '  Me![Part Number Label].Visible = False
        Me![Item Number Label].Visible = False
        Me![Comments Label].Visible = False
    End If
   
    If Me![CDRL Type] = "Non-Approval" Or Me![CDRL Type] = "For Review" Or Me![CDRL Type] = "Customer Request" Then
    Me![Label75].ForeColor = 0
    Me![Response Due].ForeColor = 0
    Me![Label68].ForeColor = 0
    Me![CDRL Type].ForeColor = 0
   
    If Me![CDRL Type] <> "Approval" Then
       Me![Response Due].Visible = False
       Me![Label75].Visible = False
    Else
       Me![Label75].ForeColor = lngRed
       Me![Response Due].ForeColor = 255
       Me![Label68].ForeColor = 255
       Me![CDRL Type].ForeColor = 255
       If Me![XMTL Date] <> Me![Response Due] Then
          Me![Response Due].Visible = True
          Me![Label75].Visible = True
       Else
          Me![Response Due].Visible = False
          Me![Label75].Visible = False
       End If
    End If
   
    If Me![CDRL Type] <> "Concurrence" Then
       Me![Response Due].Visible = False
       Me![Label75].Visible = False
    Else
       Me![Label75].ForeColor = 255
       Me![Response Due].ForeColor = 255
       Me![Label68].ForeColor = 255
       Me![CDRL Type].ForeColor = 255
       If Me![XMTL Date] <> Me![Response Due] Then
          Me![Response Due].Visible = True
          Me![Label75].Visible = True
       Else
          Me![Response Due].Visible = False
          Me![Label75].Visible = False
       End If
    End If

    If IsNull(Me![DID Number]) Then
        Me![DID Number].Visible = False
        Me![Label114].Visible = False
    Else
        Me![DID Number].Visible = True
        Me![Label114].Visible = True
    End If

    Me![CDRLNbr] = calc_cdrl([CDRL Number], [Expr1], [Expr2])
End If
End Sub
 
Last edited by a moderator:
Sorry, error
Me![Label75].ForeColor = lngRed shold be Me![Label75].ForeColor = 255
 
For simplicity, may I suggest you look into a SELECT CASE construct? (Based on Me.[CDRL Type] for about 3/4 of the cases you show.) Trying to decompose the logic of IF-ladders can be a real pain in the patootie. And if needed, you COULD nest SELECT CASE just like you can nest IF THEN ELSE groupings. Further, you have two nested IF-ladders that relate to [CDRL Type] and it is possible for you to pick one of the options from EACH of the ladders.

Then, there is the other factor... that in this format it is hard for us to read your code because you didn't use code tags... (looks like < / > in the icon bar for the post.) So the proper indentation isn't shown either.
 
Sorry, I inherited this code and trying to fix it.

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


    If Me![Expr3] = 1 Then
       ' Me![Part Number Label].Visible = True
        Me![Item Number Label].Visible = True
        Me![Comments Label].Visible = True
    Else
      '  Me![Part Number Label].Visible = False
        Me![Item Number Label].Visible = False
        Me![Comments Label].Visible = False
    End If
    
    If Me![CDRL Type] = "Non-Approval" Or Me![CDRL Type] = "For Review" Or Me![CDRL Type] = "Customer Request" Then
    Me![Label75].ForeColor = 0
    Me![Response Due].ForeColor = 0
    Me![Label68].ForeColor = 0
    Me![CDRL Type].ForeColor = 0
    
    If Me![CDRL Type] <> "Approval" Then
       Me![Response Due].Visible = False
       Me![Label75].Visible = False
    Else
       Me![Label75].ForeColor = 255
       Me![Response Due].ForeColor = 255
       Me![Label68].ForeColor = 255
       Me![CDRL Type].ForeColor = 255
       If Me![XMTL Date] <> Me![Response Due] Then
          Me![Response Due].Visible = True
          Me![Label75].Visible = True
       Else
          Me![Response Due].Visible = False
          Me![Label75].Visible = False
       End If
    End If
    
    If Me![CDRL Type] <> "Concurrence" Then
       Me![Response Due].Visible = False
       Me![Label75].Visible = False
    Else
       Me![Label75].ForeColor = 255
       Me![Response Due].ForeColor = 255
       Me![Label68].ForeColor = 255
       Me![CDRL Type].ForeColor = 255
       If Me![XMTL Date] <> Me![Response Due] Then
          Me![Response Due].Visible = True
          Me![Label75].Visible = True
       Else
          Me![Response Due].Visible = False
          Me![Label75].Visible = False
       End If
    End If

    If IsNull(Me![DID Number]) Then
        Me![DID Number].Visible = False
        Me![Label114].Visible = False
    Else
        Me![DID Number].Visible = True
        Me![Label114].Visible = True
    End If

 '   Me![CDRLNbr] = calc_cdrl([CDRL Number], [Expr1], [Expr2])
End If
End Sub
 
What recent changes took place? Can't see anything specific wrong with code. Have you step debugged?

If you want to provide db for analysis, follow instructions at bottom of my post.
 
Last edited:
It stopped working and I am not sure why. If anyone can point out why it doesn't turn RED it would be helpful.

A few years ago, I wrote some code to change label colours, but it didn't work? It turned out "IT WAS WORKING" but the background colour of the label was set to "TRANSPARENT" Therefore I couldn't see the colours change. I'm wondering if that's what's happening here?

I did a YouTube about it:-


And a blog:-


 
Here's the same code refactored with all the repetition removed...
Code:
Private Sub Detail1_Format(Cancel As Integer, FormatCount As Integer)
    Me![Comments Label].Visible = Me![Expr3] = 1
    Me![Item Number Label].Visible = Me![Comments Label].Visible
    
    Select Case Me![CDRL Type]
    Case "Non-Approval", "For Review", "Customer Request"
        SetBlockColor 0
        
        If Me![CDRL Type] = "Approval" Or Me![CDRL Type] = "Concurrence" Then
            SetBlockColor 255
            SetResponseDue Me![XMTL Date] <> Me![Response Due]
        Else
            SetResponseDue False
        End If

        Me![Label114].Visible = Not IsNull(Me![DID Number])
        Me![DID Number].Visible = Me![Label114].Visible
    End Select
End Sub

Private Sub SetResponseDue(State As Boolean)
    Me![Response Due].Visible = State
    Me![Label75].Visible = State
End Sub

Private Sub SetBlockColor(Color As Long)
    Me![Label75].ForeColor = Color
    Me![Response Due].ForeColor = Color
    Me![Label68].ForeColor = Color
    Me![CDRL Type].ForeColor = Color
End Sub
See if that isn't easier to work with. Took about 10 mins.
 
If the database is not proprietary, would it be possible to get a copy of it? I am very interested in CDRL tracking.
 

Users who are viewing this thread

Back
Top Bottom