Change the BackColor of the textbox in MS Access Report

F

FA

I have a problem, with the textbox color change in the report. I have
the following code where
FINDG_RSK_LVL is a textbox in the report. I want the color of this
textbox to be change according to the value. On report may have many
FINDG_RSK_LVL values and its values can be High, Medium, Low. I want
the color of this textbox to be changed according to the value.
The report look like this for example
System Name Finding Risk Level Count of Rsk_Lvl
Application Foo
High (2)
Medium (1)
Low (2)

Its not working i tried it in OnActivate EventProcedure as well and it
didnt work.

Private Sub Report_Open(Cancel As Integer)

If Me.FINDG_RSK_LVL.Value = "High" Then
Me.FINDG_RSK_LVL.BackColor = 255
End If
End Sub

If FINDG_RSK_LVL.Value = "Medium" Then
Me.FINDG_RSK_LVL.BackColor = 33023
End If

If FINDG_RSK_LVL.Value = "Low" Then
Me.FINDG_RSK_LVL.BackColor = 65535
End If
 
G

George Nicholson

You don't say what section FINDG_RSK_LVL is in but Report_Open is the wrong
place for your code. During Report_Open, FINDG_RSK_LVL probably doesn't have
*any* value so none of your statements return True which means no Backcolors
are changed.

1) Put the code in the Format event of whatever report section (Detail,
Header, Footer) the FINDG_RSK_LVL textbox is in.

2) Consider changing your code to a Select Case statement:

Select Case Me.FINDG_RSK_LVL.Value
Case = "High"
Me.FINDG_RSK_LVL.BackColor = 255
Case = "Medium"
Me.FINDG_RSK_LVL.BackColor = 33023
Case = "Low"
Me.FINDG_RSK_LVL.BackColor = 65535
Case Else
' Without this: if the textbox has none of the expected values
above,
' the backcolor would remain the same as whatever it was last set
to.
Me.FINDG_RSK_LVL.BackColor = 16777215
End Select

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top