Sub SetFormatConditionsForm()
Dim frm As Form
Dim i As Integer
On Error GoTo ErrNumber
Set frm = Form_фпПоискЗаявок
'если есть условное форматирование, удаляем его
If Form_фпПоискЗаявок.КодЗаявки.FormatConditions.Count > 0 Then
For i = 0 To frm.Controls.Count - 1 'ищем комбобоксы и текстбокы среди контролов
If (frm.Controls(i).ControlType = acComboBox) Or (frm.Controls(i).ControlType = acTextBox) Then
With frm.Controls(i)
.FormatConditions.Delete
End With
End If
Next i
Else
'красим только поле "КодЗаявки"
Form_фпПоискЗаявок.КодЗаявки.FormatConditions.Add acExpression, , "[КодЗаявки] = [ЦветнойУказатель]"
Form_фпПоискЗаявок.КодЗаявки.FormatConditions(0).BackColor = RGB(255, 153, 0)
'дальше красим все поля
For i = 0 To frm.Controls.Count - 1 'ищем комбобоксы и текстбокы среди контролов
If (frm.Controls(i).ControlType = acComboBox) Or (frm.Controls(i).ControlType = acTextBox) Then
If frm.Controls(i).Name = "КодЗаявки" Then
'проходим мимо
Else
With frm.Controls(i)
If (Form_фпПоискЗаявок.СтатусЗаявки = "В работе" And Form_фпПоискЗаявок.СостояниеЗаявки = "Просрочено") Then
.FormatConditions.Add acExpression, , "[СтатусЗаявки]='В работе' And [СостояниеЗаявки]='Просрочено'"
If (frm.Controls(i).Name = "НомерЗаявки") Or (frm.Controls(i).Name = "НомерРодРЗ") Then
.FormatConditions(0).FontUnderline = True
.FormatConditions(0).ForeColor = vbBlue 'RGB(0, 0, 255)
Else
.FormatConditions(0).ForeColor = vbWhite
End If
.FormatConditions(0).BackColor = RGB(255, 0, 0) 'vbRed
End If
'----------------------
If (Form_фпПоискЗаявок.СтатусЗаявки = "Закрыто") Then
.FormatConditions.Add acExpression, , "[СтатусЗаявки]='Закрыто'"
If (frm.Controls(i).Name = "НомерЗаявки") Or (frm.Controls(i).Name = "НомерРодРЗ") Then
.FormatConditions(0).FontUnderline = True
.FormatConditions(0).ForeColor = vbBlue 'RGB(0, 0, 255)
Else
.FormatConditions(0).ForeColor = vbWhite
End If
.FormatConditions(0).BackColor = RGB(34, 139, 34) 'vbGreen
End If
'----------------------
If (Form_фпПоискЗаявок.СтатусРодРЗ = "В работе" And Form_фпПоискЗаявок.СостояниеРодРЗ = "Просрочено") Then
.FormatConditions.Add acExpression, , "[СтатусРодРЗ]='В работе' And [СостояниеРодРЗ]='Просрочено'"
If (frm.Controls(i).Name = "НомерЗаявки") Or (frm.Controls(i).Name = "НомерРодРЗ") Then
.FormatConditions(0).FontUnderline = True
.FormatConditions(0).ForeColor = vbBlue 'RGB(0, 0, 255)
Else
.FormatConditions(0).ForeColor = vbWhite
End If
.FormatConditions(0).BackColor = RGB(255, 0, 0) 'vbRed
End If
'----------------------
If (Form_фпПоискЗаявок.СтатусРодРЗ = "Закрыто") Then
.FormatConditions.Add acExpression, , "[СтатусРодРЗ]='Закрыто'"
If (frm.Controls(i).Name = "НомерЗаявки") Or (frm.Controls(i).Name = "НомерРодРЗ") Then
.FormatConditions(0).FontUnderline = True
.FormatConditions(0).ForeColor = vbBlue 'RGB(0, 0, 255)
Else
.FormatConditions(0).ForeColor = vbWhite
End If
.FormatConditions(0).BackColor = RGB(34, 139, 34) 'vbGreen
End If
End With
End If
End If
Next i
End If
DoCmd.GoToControl (frm.Name)
ExitHeare:
Set frm = Nothing
Exit Sub
ErrNumber:
If Error <> 0 Then
MsgBox "Процедура: SetFormatConditionsForm." & vbCrLf & _
Err.Description, , "№ " & Err.Number
Resume ExitHeare
End If
End Sub
|