Conditional Formats on a Form

Gary_Mc_Mahon

Board Regular
Joined
Apr 30, 2003
Messages
87
Hi,

I want my form to change background colour if a particular value exists in a field.

Under the properties of the form I not sure which event would best suit this.

Any tips.

My code will go something like

If forms![frm_Account_Screen]![Acct_OnHold]= True Then
frm_Account_Screen detail section format background = 255 ' Some tips on this line would be good.
Else
Exit Sub
End If

Cheers
Gary
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Gary,
one way is to use the Form's Current event. Something like:
Code:
Private Sub Form_Current()
  If [City] = "Provo" Then
    Me.Detail.BackColor = 255
  Else
    Me.Detail.BackColor = 0
  End If
End Sub
That switches the background between red (for those records meeting the criteria) and black (for those not meeting them. Note; you must be using a plain form, with none of the autoformats employed. because the Autoformat images will override the colour changes.
You should also put the code in the AfterUpdate event of the control whose value triggers the format change.

Denis
 
Upvote 0

Forum statistics

Threads
1,221,810
Messages
6,162,108
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top