I have put the following code together using info found on this forum but I can't get it work correctly so help would be appreciated.
If I have a single IF statement then the code works for both options but when I try and put the two together as above the If Me!FertRecStatus option works but the If Me!NoLongerCropped doesn't work.
Thank you in advance for any suggestions
Neil
Code:
Private Sub Form_Current()
'varCondition must be numeric for this to work
Dim ctl As Control, strForm As String, varCondition As Variant
Dim fcs As FormatConditions, fc As FormatCondition
Dim lngColour As Long
Dim lngColour2 As Long
Dim Font As Long
On Error Resume Next
varCondition = Me!CroppingNumber
'This code overrides the conditional formatting appplied WHEN the records have focus using the Cropping Number
If Me!NoLongerCropped = True Then
lngColour = vbBlack 'black background
lngColour2 = vbRed 'Red font
Font = False 'Font is normal
End If
'Code if cropping is provisional
If Me!FertRecStatus = -1 Then
lngColour = vbWhite 'white background
lngColour2 = vbRed 'Red font
Font = True 'Font is bold
Else
lngColour = vbWhite 'white background
lngColour2 = vbBlack 'Black Font
Font = True 'Font is bold
End If
For Each ctl In Me.Controls
If ctl.Tag = "ConditionalFormat" Then
Set fcs = Me.Controls(ctl.Name).FormatConditions
fcs.Delete 'Deletes any other Conditional Formatting, limit is 3
Set fc = fcs.Add(acExpression, , "CroppingNumber=" & varCondition)
fc.BackColor = lngColour
fc.ForeColor = lngColour2
fc.FontBold = Font
End If
Next ctl
Dim ParentDocName As String
On Error Resume Next
ParentDocName = Me.Parent.Name
If Err <> 0 Then
GoTo Form_Current_Exit
Else
On Error GoTo Form_Current_Err
Me.Parent![frmIfSfFertAppln1].Requery
End If
Form_Current_Exit:
Exit Sub
Form_Current_Err:
MsgBox Error$
Resume Form_Current_Exit
End Sub
Thank you in advance for any suggestions
Neil