X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Code Needed To Chane Colour Of A Form, Access 2016    
post May 15 2018, 09:54 AM

Posts: 25
Joined: 17-June 14
From: Kent, UK

Hi I wonder if you can help me please?

I currently have code that makes the form change colour when the individual is marked inactive.

I would like to add an additional command to change the form to a different colour if another field is populated.

This is the code I have in the form properties:

Private Sub Form_Current()
On Error GoTo Form_Current_Error

If Me.Status.Column(1) = "Inactive" Then
Me.Section(acDetail).BackColor = vbRed

Me.Section(acDetail).BackColor = vbGreen

End If

On Error GoTo 0
Exit Sub

What do I need to add please if the field in question is populated with a 1 active please?

Does that make sense? Do I add new code? I'm not sure what colour its currently red if they are inactive and the normal is green indicating they are green/active. Maybe yellow or purple.

Thank you

Thank you for your help and patience,
Go to the top of the page
Doug Steele
post May 15 2018, 10:03 AM

UtterAccess VIP
Posts: 21,736
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Private Sub Form_Current()
On Error Resume Next
  Select Case Me.Status.Column(1)
    Case "Inactive"
      Me.Section(acDetail).BackColor = vbRed
    Case "Active"
      Me.Section(acDetail).BackColor = vbYellow
    Case Else
      Me.Section(acDetail).BackColor = vbGreen
  End Select
Exit Sub

Note that I removed the lines On Error GoTo Form_Current_Error and On Error GoTo 0. I'm actually surprised you didn't get a compile error, since no label Form_Current_Error existed in the module!

Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    26th May 2018 - 05:14 AM