FormatConditions, help needed

  • Thread starter Thread starter Ingo Streek
  • Start date Start date
I

Ingo Streek

Hello,

In Access 2002, I have set up a report with several text boxes. Now, I would
like to assign a specific format (bold, background colour) to one of the
textboxes (named 'BE') depending on its content, and this I want to realize
by a macro.

I don't understand the HELP text of MS how to do that, and googeling did not
produce any results, either.

The following code does not work:

Dim strBE(4) As String, stDocName As String, _
fmc As FormatCondition, _
objBericht as object

strBE(1) = "Value1"
strBE(2) = "Value2"

Set objBericht = Application.Reports("Tabelle1")
Set fmc = objBericht.FormatConditions.Add(acFieldValue, acEqual,
(objBericht.BE.Text = strBE(1)))

Can anybody please post a few lines of code, how to change the format of a
textfield depending on its content?

Thanks
Ingo
(Apologies for my English, it's not my native language)
 
Since you're using Access 2002, if you don't need more than 4 formats you
can use the built-in conditional formatting. Right click the textbox in
design mode and choose Conditional Formatting from the popup menu. Fill in
the items as desired. You can have a default format plus 3 others.

To do this in code, use the Format event of the report section that the
textbox is in. You would then set up and If statement or Select Case
statement (whichever is easier for you) to assign the formats.

Example:
With Me.txtMyTextbox
Select Case .Value
Case 1
.BackColor = vbRed
.ForeColor = vbGreen
Case 3
.BackColor = vbWhite
.ForeColor = vbBlack
Case Else
.BackColor = vbBlue
.ForeColor = vbWhite
End Select
End With
 
Thanks a lot, this helped to solve my problem!

Wayne Morgan said:
Since you're using Access 2002, if you don't need more than 4 formats you
can use the built-in conditional formatting. Right click the textbox in
design mode and choose Conditional Formatting from the popup menu. Fill in
the items as desired. You can have a default format plus 3 others.

To do this in code, use the Format event of the report section that the
textbox is in. You would then set up and If statement or Select Case
statement (whichever is easier for you) to assign the formats.

Example:
With Me.txtMyTextbox
Select Case .Value
Case 1
.BackColor = vbRed
.ForeColor = vbGreen
Case 3
.BackColor = vbWhite
.ForeColor = vbBlack
Case Else
.BackColor = vbBlue
.ForeColor = vbWhite
End Select
End With
 
Back
Top