UtterAccess.com
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    
 
   
Clairh11
post May 15 2018, 09:54 AM
Post#1



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

Else
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
Clair

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


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


Try:

CODE
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!

--------------------
Doug Steele, Microsoft Access MVP (2000-2018)
http://www.accessmvp.com/DJSteele/AccessIndex.html
Co-author: Access Solutions: Tips, Tricks, and Secrets from Microsoft Access MVPs, published by Wiley
Co-author: Effective SQL: 61 Specific Ways to Write Better SQL, published by Addison-Wesley Professional
Technical Editor: Access 2010 Bible, Access 2013 Bible, Access 2016 Bible, all published by Wiley
Technical Editor: SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, 4th Edition, published by Addison-Wesley Professional
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    16th August 2018 - 01:02 AM