Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Trying to turn font bold and red if certain criteria exists

I have this code in the oncurrent event of a form;

    If Me.cboHBA1Code <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'R'") Then
        Me.cboHBA1Code.ForeColor = vbRed
        Me.cboHBA1Code.FontBold = True
        Else
        Me.cboHBA1Code = vbBlack
        Me.cboHBA1Code.FontBold = False
    End If

Open in new window


But there are 8 different "acceptable" codes in tblTreatmentCodes.  I tried replacing the "R" with '*' as a wildcard but that doesn't work.

Do I have to do a DLookup on all eight so the code looks like:

    If Me.cboHBA1Code <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'R'") OR <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'O'") OR <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'C'") OR <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'NM'") OR <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'D'") OR <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'X'") OR <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'H'") OR <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= 'Ref'") Then
        Me.cboHBA1Code.ForeColor = vbRed
        Me.cboHBA1Code.FontBold = True
        Else
        Me.cboHBA1Code = vbBlack
        Me.cboHBA1Code.FontBold = False
    End If

Open in new window

Avatar of Randy Poole
Randy Poole
Flag of United States of America image

Try this:
If Me.cboHBA1Code <> DLookup("[CodeAbbreviation]", "tblTreatmentCodes", "[CodeAbbreviation]= '" & Me.cboHBA1Code & "'") Then
        Me.cboHBA1Code.ForeColor = vbRed
        Me.cboHBA1Code.FontBold = True
        Else
        Me.cboHBA1Code = vbBlack
        Me.cboHBA1Code.FontBold = False
End if

Open in new window

Avatar of Rey Obrero (Capricorn1)
use this codes instead

select case Me.cboHBA1Code
       Case "R","O","C","NM","D","X","H","Ref"
        Me.cboHBA1Code.ForeColor = vbRed
        Me.cboHBA1Code.FontBold = True

       Case Else
        Me.cboHBA1Code = vbBlack
        Me.cboHBA1Code.FontBold = False
end select
Avatar of SteveL13

ASKER

For some reason that code is turning the data into a 0 (zero).  It is really a R in the table.
My reply was to Randy.  I'll try Rey's.
Using Rey's code...  (note that the logic was reversed.  If the data is "R", "O", "C", "NM", "D", "X", "H", or "Ref" then it should be vbBlack and FontBold = False)

But if the data is not "R", "O", "C", "NM", "D", "X", "H", or "Ref" then the form shows "255"

????

Here is what I have now...

   
Select Case Me.cboHBA1Code
        Case "R", "O", "C", "NM", "D", "X", "H", "Ref"
        Me.cboHBA1Code.ForeColor = vbBlack
        Me.cboHBA1Code.FontBold = False
        Case Else
        Me.cboHBA1Code = vbRed
        Me.cboHBA1Code.FontBold = True
    End Select

Open in new window

SOLUTION
Avatar of PatHartman
PatHartman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ohh sorry.. need more coffee..

does it work now?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect!!!!!