Avatar of Fordraiders
Fordraiders
Flag for United States of America

asked on 

issue with conditional foirmatting and code reading a string as a numeric

access 2010 vba
sql server

I have a linked that from sql server that has a field  that is stored as a string unfortunately..TARGET_GP

"Line_Color" IS STRING FIELD ALSO , BUT JUST GETTING UPDATED depending on the code, not conditional formatting

So when conditional formatting is looking at the value it does not evaluate correctly when the value is between 0.01 and 9.99
or the code below:

Dim gp As String
  

    If Len(Nz(Me.TARGET_GP, "")) = 0 Then
   Exit Sub
End If
Me!TARGET_GP = Replace([TARGET_GP], "%", "")
Me!TARGET_GP = Replace([TARGET_GP], "..", ".")
If IsNumeric(Me.TARGET_GP) = True Then
    Me.TARGET_GP.Value = Format(Me.TARGET_GP.Value / 100, "0.00%")
End If


If Me!TARGET_GP = "%" Then
Me!TARGET_GP = ""
End If


gp = Me.TARGET_GP.Value



Me!Line_Color = ""


If gp <= "14.99%" Then
  MsgBox "Sorry But the Target_Gp is Below Threshold. Please Correct.", vbCritical, "TARGET THRESHOLD"
  LINE_GP_FAILS = False
  Me.Line_Color = "RED"

End If

' red Light
If gp >= "15.00%" And gp <= "19.99%" Then
  '  MsgBox "RED dave"
    LINE_GP_FAILS = False
    Me.Line_Color = "RED"

End If

' Yellow Light
If gp >= "20.00%" And gp <= "24.99%" Then
  ' MsgBox "yELLOW"
   LINE_GP_FAILS = False
   Me.Line_Color = "YELLOW"

End If

' green light
If gp >= "25.00%" Then
 ' MsgBox "gREEN"
  LINE_GP_FAILS = False
  Me.Line_Color = "GREEN"

End If
   
   
   Exit Sub

Open in new window

Microsoft AccessVBA

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon