Conditional Formatting?

unit213

Active Member
Joined
Jul 11, 2003
Messages
427
I’m completely new to Access so forgive me. I have decent Excel skills though just to give you some background.

I am working on a project that requires the cell background to turn red when specific number goes negative.

Is there any conditional format type code that can be written to do this?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I believe you can change the color of controls on Forms and Reports, but it will have to be with VBA code. I don't believe Access has anything like Conditional Formatting.
 
Upvote 0
Actually, if you happen to use Access 2000 or newer, there is Conditional Formatting much like Excel found in the Format menu.
 
Upvote 0
If you need the code, the following should work:

In a report: (FORMAT event of the DETAIL section)

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.YourFieldName < 0 Then
Me.YourTextBox.BackColor = vbRed
Else
Me.YourTextBox.BackColor = vbWhite
End If
End Sub

or, in a form's CURRENT event: (Note, this will only work in Single Form view. Continuous forms make it much more complicated)

Private Sub Form_Current()
If Me.YourFieldName < 0 Then
Me.YourTextBox.BackColor = vbRed
Else
Me.YourTextBox.BackColor = vbWhite
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,621
Messages
6,160,879
Members
451,675
Latest member
Parlapalli

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