Full Version: Conditional formatting in vba help
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Dave1816
Dim objFrc As FormatCondition

Hello, I am currently stuck trying to highlight a field using conditional formatting in VBA. What I would like to do is highlight the field "Firstname" if it is equal to dave. However, i have two problems:

1st being the colour used to highlight is highlighting all cells and not just cell with "Dave" only

2nd being the highlight only works when selecting a field with value "Dave" in.


Any ideas why this is happening?

Code is listed below

Hope you can help

Many Thanks

Dave


Dim lngYellow As Long

' Set colors to variable.

lngYellow = RGB(255, 255, 0)

' Remove any existing format conditions.
Me![Firstname].FormatConditions.Delete

' Create 1 format objects and add them to the FormatConditions


Set objFrc = Me![Firstname].FormatConditions.Add(acExpression, , hello = "dave")
' Refer to each format condition by its index.

With Me![Firstname].FormatConditions(0)
.BackColor = lngYellow
End With
Jeff B.
Remember that Access doesn't have "cells" (that's Excel)...

If I remember correctly, you have to use RTF to get a portion of a text string formatted differently from another part.
Dave1816
not sure what an rtf is m8 but you can change the conditional formatting in access but just cant seem do it by code

Heres an example website showing how to do it http://msdn.microsoft.com/en-us/library/aa...office.10).aspx

but just cant seem get mine work,lol
Dave1816
ive manage to get it work whe numbers are involved but not text, has any 1 got any ideas why? the codes below many thanks dave

Dim objFrc As FormatCondition

Dim lngYellow As Long

' Set colors to variable.

lngYellow = RGB(255, 255, 0)

' Remove any existing format conditions.
Me![Firstname].FormatConditions.Delete

Set objFrc = Me.Firstname.FormatConditions.Add(acFieldValue, acEqual, 1)



With Me![Firstname].FormatConditions(0)
.BackColor = lngYellow
End With

' With Me![Firstname].formaFormatConditions(0)
'' .BackColor = lngYellow
' End With

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.