Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with code please 1

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
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.
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
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
 
PErhaps this ?
Code:
If Me!FertRecStatus = -1 Then
    lngColour = vbWhite 'white background
    lngColour2 = vbRed 'Red font
    Font = True 'Font is bold
ElseIf Me!NoLongerCropped = True Then
    lngColour = vbBlack 'black background
    lngColour2 = vbRed 'Red font
    Font = False 'Font is normal
Else
    lngColour = vbWhite 'white background
    lngColour2 = vbBlack 'Black Font
    Font = True 'Font is bold
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you for the prompt response. That works fine.

The black background and red font was only used as a contrast while I got the code sorted so now to change it to something a bit easier on the eye.

Thanks again

Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top