我正在使用MS Access进行数据库管理。我有几个链接表生成不同的报告。我已经在stackoverflow上找到了一个类似的问题,并就此问题进行了重新考虑。我试图根据条件绘制行(持续时间< 20 Paint Beige,2060 Red)
我正在使用VBasic。这是我的代码。
请让我知道你的想法。非常感谢你的帮助!
Sub ChangeBackType()
Me.Date.BackStyle = 1
Me.Cell.BackStyle = 1
Me.Maintenance_Category.BackStyle = 1
Me.Duration.BackStyle = 1
Me.Line_Description.BackStyle = 1
Me.Machine_Description.BackStyle = 1
Me.Station_Number.BackStyle = 1
Me.Fault_Description.BackStyle = 1
Me.GM.BackStyle = 1
Me.Remarks.BackStyle = 1
Me.Intervention.BackStyle = 1
Me.Technician_Name.BackStyle = 1
Me.Shop_Floor.BackStyle = 1
End Sub
Sub Paint_Rows_Red()
'与其他颜色相同的方法
Me.Date.BackColor = RGB(255, 29, 29)
Me.Cell.BackColor = RGB(255, 29, 29)
Me.Maintenance_Category.BackColor = RGB(255, 29, 29)
Me.Duration.BackColor = RGB(255, 29, 29)
Me.Line_Description.BackColor = RGB(255, 29, 29)
Me.Machine_Description.BackColor = RGB(255, 29, 29)
Me.Station_Number.BackColor = RGB(255, 29, 29)
Me.Fault_Description.BackColor = RGB(255, 29, 29)
Me.Intervention.BackColor = RGB(255, 29, 29)
Me.GM.BackColor = RGB(255, 29, 29)
Me.Remarks.BackColor = RGB(255, 29, 29)
Me.Technician_Name.BackColor = RGB(255, 29, 29)
Me.Shop_Floor.BackColor = RGB(255, 29, 29)
End Sub
Private Sub Report_Load()
ChangeBackType
Dim Test As String
Test = TestString2
TestString2 = Me!Duration.Value
TestString2 = FormatDateTime(TestString2, vbShortTime)
If TestString2 <= CDate("00:20") Then
Paint_Rows_Beige
ElseIf TestString2 > CDate("00:20") And TestString2 < CDate("00:60") Then
Paint_Rows_Orange
ElseIf TestString2 >= CDate("00:60") Then
Paint_Rows_Red
End If
我试图根据报告中提到的条件绘制行。使用此代码,我只得到一种颜色..
答案 0 :(得分:2)
当您打开包含多行的报表/表单时,您使用的代码将仅应用于数据中出现的第一行。简而言之,您的代码将无效。
但是有一种方法可以使用条件格式为不同条件的行着色。