SteveL13
asked on
Trying to turn font bold and red if certain criteria exists
I have this code in the oncurrent event of a form;
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'") Then
Me.cboHBA1Code.ForeColor = vbRed
Me.cboHBA1Code.FontBold = True
Else
Me.cboHBA1Code = vbBlack
Me.cboHBA1Code.FontBold = False
End If
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
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
select case Me.cboHBA1Code
Case "R","O","C","NM","D","X","
Me.cboHBA1Code.ForeColor = vbRed
Me.cboHBA1Code.FontBold = True
Case Else
Me.cboHBA1Code = vbBlack
Me.cboHBA1Code.FontBold = False
end select
ASKER
For some reason that code is turning the data into a 0 (zero). It is really a R in the table.
ASKER
My reply was to Randy. I'll try Rey's.
ASKER
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...
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ohh sorry.. need more coffee..
does it work now?
does it work now?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect!!!!!
Open in new window