Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I highlight duplicate field values on a form.

Status
Not open for further replies.

nullig

Technical User
Jan 20, 2004
10
0
0
CA
I have a form linked to a table with two fields "UserCode" and "UserName". I am trying to set the Field Backcolor to red where the UserCode data is the same. I can't find any way through conditional formatting, so I assume I'd need some code to do it.

Can anyone suggest a way to do this?
Thanks.
 
The place to do the formating is in the Detail_Format event on the form (or if your controls are in a Header/footer then in the respective _format event.)

I have used this previously to display a comment if certain criteria are met within the record.

The principle would be the same - I have found that the control properties for formating do not show up on code so you have to "Guess" the appropriate ones -

.FontColor
.Fontbold = true/false

as the ones that come to mind,

Hope that this helps

 
I guess I wasn't clear on the problem. I know how to do the formatting... I just need to figure out how to determine which fields have duplicate entries and then apply the formatting.
 
Have you tried the DCount function ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Can you give me an example of using the DCount function?
 
here is an example of one I use


Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)


Dim intCount As Integer
intCount = DCount("[txtMarket]", "tblITSMarketInfo", "[txtMarket]='" & Me![ctlMarket] & "'")

If intCount > 2 Then
   Me.lblMarketCount.ForeColor = vbRed

Else
    Me.lblMarketCount.ForeColor = vbBlue

End If
End Sub

Where [txtMarket] is the feild name
"tblITSMarketInfo" is the underlying Table name and
"me![ctlMarket]" is the field on the report for the current record.

There are further examples of how to build the Critera in the Access Help Files.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top