Link to home
Start Free TrialLog in
Avatar of John Pike
John PikeFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Form Background colour change

Access 2003 , I have a form which is light grey background and I wish to change this background colour for the form
based on a field within the form. The field is a Y or N called 'Invoiced' .
So if invoiced = y form should change colour if = N no change.

Many Thanks for any help
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

for example, in the Form_Current event, try add:
Private Sub Form_Current()
    If iniColor = 0 Then iniColor = Me.BackColor
     If Invoiced.Value = "Y" Then
       'Set the color you want
        Me.BackColor = RGB(255, 0, 0)
    Else
        Me.BackColor = iniColor
    End If
End Sub

Open in new window

In a public Module:
Public iniColor As Long

Open in new window

or you probably can do it via Conditional Formatting in Access.
Avatar of John Pike

ASKER

Thanks Ryan but it comes back with a compile error
'Method or data not found and halts on the first If line at   .BackColor

Regards
sorry it says  Data Member not found
sorry, try this instead.
Public iniColor As Long

Private Sub Form_Current()
    If iniColor = 0 Then iniColor = Me.Section(acDetail).BackColor
    If Invoiced.Value = "Y" Then
        'Set the color you want
        Me.Section(acDetail).BackColor = RGB(255, 0, 0)
    Else
        Me.Section(acDetail).BackColor = iniColor
    End If
End Sub

Open in new window

Hi Ryan
This works when it finds a reord with  Invoiced = "Y" but when the next record
has Invoiced="N" it does not change back

Have I missed something

regards
for your info Original Form Colour = RGB 219,219,219
changed colour is 179,179,179
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ryan,
many thanks that appears to work a treat...excellent