Hello,
I would like to loop over the rows of a form and check in each row the value of 1 column; depending on this value, the cell (for the corresponding row and column) should change color. This procedure should be done when the form is opened so that we can see the colored cells as soon as we open the form.
Thank you for your help,
Regards
Hi
Have you considered conditional formating?
This would seem to be the application for which it is designed!
If you need any help with that then let us know.
MTB
4 2366
Hi
Have you considered conditional formating?
This would seem to be the application for which it is designed!
If you need any help with that then let us know.
MTB
Thank you so much for your reply,
I did not know about conditional formatting (I am new to access VBA); I did a search on it and now it is working perfectly!
Attached is the code; it could be helpful for people who might have the same question.
Regards, - Option Compare Database
-
Option Explicit
-
-
Const GreenG As Byte = 1
-
-
Const OrangeO As Byte = 2
-
-
Const RedR As Byte = 3
-
-
-
Private Sub StartCondFormatting()
-
-
Dim objFrc As FormatCondition
-
-
Const orange As Long = 42495
-
-
Const green As Long = 25600
-
-
Const red As Long = 255
-
-
Dim ctl As Control
-
-
-
-
For Each ctl In Me.Controls
-
-
If ctl.Tag = "Conditional" Then
-
-
With ctl
-
-
'Remove format conditions
-
-
.FormatConditions.Delete
-
-
-
-
'Create three format objects and add them to the FormatConditions
-
-
Set objFrc = .FormatConditions.Add(acExpression, acEqual, "[fieldName] = " & GreenG)
-
-
Set objFrc = .FormatConditions.Add(acExpression, acEqual, "[fieldName] = " & OrangeO)
-
-
Set objFrc = .FormatConditions.Add(acExpression, acEqual, "[fieldName] = " & RedR)
-
-
-
-
'Specify the formating conditions
-
-
.FormatConditions(0).BackColor = green
-
-
.FormatConditions(0).Enabled = True
-
-
.FormatConditions(1).BackColor = orange
-
-
.FormatConditions(1).Enabled = True
-
-
.FormatConditions(2).BackColor = red
-
-
.FormatConditions(2).Enabled = True
-
-
End With
-
-
End If
-
-
Next ctl
-
-
Set objFrc = Nothing
-
-
-
End Sub
-
-
-
-
Private Sub Form_Load()
-
StartCondFormatting
-
End Sub
https://accessexperts.com/blog/2011/...ng-using-code/
I am glad that helped, but I must confess I have never seen or considered doing it in code. That in itself is very interesting.
I have always set conditional formatting in design view.
As they say, you learn something new every day (well almost every day!).
MTB
NeoPa 32,556
Expert Mod 16PB
Up until 2003 there were only ever three settings for Conditional Formatting (2007 increased that to a more useful number). In that situation it made sense for various experts to develop and share code-based techniques that could do a similar job.
Since 2007 they're now mostly redundent.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jouke Langhout |
last post by:
Hello all!
For quite some time now, I've got the following problem:
Access won't close properly when a user closes the application. An
ACCESS process stays active and that process can only be...
|
by: Shaldaman |
last post by:
I have an Access form called "Login". "Command10" is a button on the
form and "Text5" is a text field on it. When a user enters a value in
the Text5 text field and clicks the button Command10, I...
|
by: dddsssdddsss |
last post by:
A comment and a question
To anyone who is using conditional formatting, beware that in Access
2007 the color pallette is not the same as the color pallette in Access
2003. So if you have a...
|
by: wongray |
last post by:
Hi,
I have an access question.
it is possible to set a formula in access to check the current date - the date field.?
Kindly advise.
Regards
Raymond
|
by: DAObermeyer |
last post by:
Hey all, first time here.
I have a database that is designed to be opened and viewed at other locations on the network.
I use Form (A) to modify Data in Table (A), and Form (B) is used scrictly...
|
by: Rhys Gottwald |
last post by:
Hi All,
I have a report that is going to have 30 odd fields each containing a number, the number is the wind speed.
I want to format the background of the field based on the value of the...
|
by: JM11 |
last post by:
Hello,
I would like to display the current date (in a field called "Latest date" in a form) when a button is pressed in that form. The field in the form has a source in a table; thus, I am trying to...
|
by: JM11 |
last post by:
Hello,
I would like to replace the character 'Â' with an empty space for all the values that belong to the column entitled 'Montant' of a form. Below is the code that I wrote but is not working. Any...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |