My Assistant
![]() ![]() |
|
|
Nov 24 2010, 07:10 PM
Post
#1
|
|
|
UtterAccess Enthusiast Posts: 57 From: United Kindom |
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 |
|
|
|
Nov 24 2010, 07:15 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 8,170 From: Pacific NorthWet |
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. |
|
|
|
Nov 24 2010, 07:22 PM
Post
#3
|
|
|
UtterAccess Enthusiast Posts: 57 From: United Kindom |
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 |
|
|
|
Nov 24 2010, 09:44 PM
Post
#4
|
|
|
UtterAccess Enthusiast Posts: 57 From: United Kindom |
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 |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 25th May 2013 - 08:30 AM |