Change Color Of Sub-Form Row (1 Viewer)

GC2010

Registered User.
Local time
Yesterday, 22:26
Joined
Jun 3, 2019
Messages
120
I have a form with a sub form on it. This sub form shows dates, I want to change the row color to red of any date that is >= 60 days from today and change the rows to yellow for any date that is between >=59 days and >= 30 days from today


I assume I’d use the form_load event but what would be the syntax?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:26
Joined
Oct 29, 2018
Messages
21,447
Hi. If you're using a continuous view form in your subform, then I don't think you can use the Load event to change the rows with different colors. Instead, you may have to use Conditional Formatting (CF). However, CF only applies to one control. So, one popular workaround is to add an empty textbox behind all the controls in the row and apply the CF rule to it.
 

GC2010

Registered User.
Local time
Yesterday, 22:26
Joined
Jun 3, 2019
Messages
120
I don’t believe the sub form is set to co tinuous view.

Conditional formatting - how would I do that?

Could I set the on load event of the sub form (which is a form itself) and when the sub form loads in the parent form the colored rows will remain?
 

missinglinq

AWF VIP
Local time
Today, 01:26
Joined
Jun 20, 2003
Messages
6,423
The same applies to a Datasheet View Form...which is likely to be the situation (assuming it's not in Continuous View) since your talking about coloring 'rows.' In that case you have to use the same advice, i.e. Conditional Formatting, but either use it to change the color of one Control, probably the Date Control, or to change the color of all Controls in the particular Record/Row.

You can do the Formatting of multiple Controls as easy a single Control.

In Design View
  1. Hold Down <SHIFT>
  2. Select each Control to be Formatted
  3. Click on Conditional on the Ribbon
  4. Under Contion1 drop down Expression Is
  5. In the next box enter you first expression
  6. Click on the Paint Bucket Icon
  7. Select the color for your first expression
  8. Click on Add
  9. Under Contion2 drop down Expression Is
  10. In the next box enter you second expression
  11. Click on the Paint Bucket Icon
  12. Select the color for your second expression
  13. Click on Add if appropriate...or OK if you're through.
Linq :0)>
 

GC2010

Registered User.
Local time
Yesterday, 22:26
Joined
Jun 3, 2019
Messages
120
The same applies to a Datasheet View Form...which is likely to be the situation (assuming it's not in Continuous View) since your talking about coloring 'rows.' In that case you have to use the same advice, i.e. Conditional Formatting, but either use it to change the color of one Control, probably the Date Control, or to change the color of all Controls in the particular Record/Row.

You can do the Formatting of multiple Controls as easy a single Control.

In Design View
  1. Hold Down <SHIFT>
  2. Select each Control to be Formatted
  3. Click on Conditional on the Ribbon
  4. Under Contion1 drop down Expression Is
  5. In the next box enter you first expression
  6. Click on the Paint Bucket Icon
  7. Select the color for your first expression
  8. Click on Add
  9. Under Contion2 drop down Expression Is
  10. In the next box enter you second expression
  11. Click on the Paint Bucket Icon
  12. Select the color for your second expression
  13. Click on Add if appropriate...or OK if you're through.
Linq :0)>

Hah - so it's the same steps as for Excel! HOOZAH!!!

I have a New Formatting Rule
Rule Type: Check values in the current record or use an expression
Format only cells where the:
Expression Is: [SourceDate] >= Date(Now()+60)
Change Back Color To Red

This gives me an error of:
The expression you entered has a function containing the wrong number of arguments

(and [SourceDate] is a field in the table and being displayed on the sub-form)
What am I setting up incorrectly here?
 

GC2010

Registered User.
Local time
Yesterday, 22:26
Joined
Jun 3, 2019
Messages
120
I have tested on ONLY my SourceDate field and have added in the criteria
Red: Value < Date()-60
Yellow: Value Between Date()-30 AND Date()-59

The only issue I have remaining is that it ONLY will backfill the SourceDate column, I want ALL textboxes on the form to have the back-color changed when the criteria is met.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:26
Joined
Oct 29, 2018
Messages
21,447
I have tested on ONLY my SourceDate field and have added in the criteria
Red: Value < Date()-60
Yellow: Value Between Date()-30 AND Date()-59

The only issue I have remaining is that it ONLY will backfill the SourceDate column, I want ALL textboxes on the form to have the back-color changed when the criteria is met.
To apply CF on a control based on a value in another control, you'll have to use an "expression." For example:
Code:
Expression Is: [ControlName] Between Date()-59 And Date()-30
Hope it helps...
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:26
Joined
Sep 21, 2011
Messages
14,216
I have tested on ONLY my SourceDate field and have added in the criteria
Red: Value < Date()-60
Yellow: Value Between Date()-30 AND Date()-59

The only issue I have remaining is that it ONLY will backfill the SourceDate column, I want ALL textboxes on the form to have the back-color changed when the criteria is met.

Either apply the same criteria to every control in the row, or use a textbox as back fill as in the Emulated Split Form DB attached.?

Edit: I see theDBguy already mentioned this in post #2?
 

Attachments

  • EmulateSplitForm v10S.accdb
    736 KB · Views: 156

GC2010

Registered User.
Local time
Yesterday, 22:26
Joined
Jun 3, 2019
Messages
120
All right! I’m very close now!!

Can someone help me with the condition for the 30 days past due?

The Source date displayed that we are checking against will always be the 1st of the month

For > 60 day accounts I am using
Expression is [SourceDate] <Date()-60

If I use
Expression is [SourceDate] Between Date()-30 and Date()-59

That skews the results bc today is not the first of the month so we are not actually altering color accurately

With the Source date Always being the 1st as the day how would my conditional formatting need to be setup to truly show accounts 30 days over due and accounts 60 days or greater over due?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:26
Joined
Oct 29, 2018
Messages
21,447
All right! I’m very close now!!

Can someone help me with the condition for the 30 days past due?

The Source date displayed that we are checking against will always be the 1st of the month

For > 60 day accounts I am using
Expression is [SourceDate] <Date()-60

If I use
Expression is [SourceDate] Between Date()-30 and Date()-59

That skews the results bc today is not the first of the month so we are not actually altering color accurately

With the Source date Always being the 1st as the day how would my conditional formatting need to be setup to truly show accounts 30 days over due and accounts 60 days or greater over due?
Hi. I think maybe you’re asking how to use the DateDiff() function here. For example:
Code:
Expression Is DateDiff([SourceDate],Date())>60
 

GC2010

Registered User.
Local time
Yesterday, 22:26
Joined
Jun 3, 2019
Messages
120
Hi. I think maybe you’re asking how to use the DateDiff() function here. For example:
Code:
Expression Is DateDiff([SourceDate],Date())>60

I think I’ve done a poor job of explanation

What my issue is, is that we are using Date() which is based off the current Fate.

I need the calculation to be based off the first day of the month

For example, the current day of the current month is no matter to the calculation. I want to show 60 days from first of month, does that make sense?

Also show between 30 and 60 days from first of month
 

Micron

AWF VIP
Local time
Today, 01:26
Joined
Oct 20, 2018
Messages
3,478
I want to show 60 days from first of month
Maybe

Code:
DateSerial(Year(#06/14/2019#),Month(#06/14/2019#), 1) + 60
where you are providing any valid date value for the month in question?
 

GC2010

Registered User.
Local time
Yesterday, 22:26
Joined
Jun 3, 2019
Messages
120
Maybe

Code:
DateSerial(Year(#06/14/2019#),Month(#06/14/2019#), 1) + 60
where you are providing any valid date value for the month in question?

That was so close! When I used your code, I kept getting the 2nd and not the first.

Example:
Code:
Debug.Print DateSerial(Year(Date), Month(Date), 1) - 60
Debug.Print DateSerial(Year(#07/14/2019#), Month(#07/14/2019#), 1) - 60

Returns
Code:
5/2/2019

Which got the wheels turning and I used

Code:
Debug.Print DateSerial(Year(Date - 60), Month(Date - 60), 1)

Which returns my desired result of:
Code:
5/1/2019
 

Users who are viewing this thread

Top Bottom