Dustin Stanley
asked on
MS Access Form Control Background Color Change Depending On How Long The String Text Length Is
Ok this might be a interesting one! I would like to add the ability of changing the background color of a specific text box control on my form depending on the length of text that is in it.
Example:
Normal basic color is white. White = Good!
Text string count reaches 76 character length then the background goes Yellow. Yellow = Warning!
Text string count reaches 150 character length then the background goes Red. Red = Maximum!
We like to keep it under 76 length but in some cases it can be longer!
My specific text box control name is "SkuNm".
How can I do this??
THANK YOU ALL!
Example:
Normal basic color is white. White = Good!
Text string count reaches 76 character length then the background goes Yellow. Yellow = Warning!
Text string count reaches 150 character length then the background goes Red. Red = Maximum!
We like to keep it under 76 length but in some cases it can be longer!
My specific text box control name is "SkuNm".
How can I do this??
THANK YOU ALL!
change the backcolor property of your field (in the keyup event) based on LEN of your field
ASKER
Thanks. Can you explain a little more about the LEN Please?
len is a built in vba function e.g. LEN("abc") = 3
place your textbox name in the braces
place your textbox name in the braces
ASKER
Also on the KeyUp event would that count the key strokes for the information? Thanks for the help!
this is based on my field txtRevs
Private Sub txtRevs_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(txtRevs.Text) > 3 Then
txtRevs.BackColor = vbRed
End If
End Sub
Private Sub txtRevs_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(txtRevs.Text) > 3 Then
txtRevs.BackColor = vbRed
End If
End Sub
ASKER
Ok that makes sense greater then 3 the message box appears. How can I integrate this with the background color scheme?
ASKER
Ok So far I have
Private Sub SkuNm_KeyUp(KeyCode As Integer, Shift As Integer)
If Len(SkuNm.Text) > 75 Then
SkuNm.BackColor = vbRed
End If
End Sub
not sure what you want?
ASKER
Ok that is not working TOTALLY! If I was to delete some of the string say back down to 74 it never changes back to white from red?
ASKER
Thanks for your help. I am looking for : Text field greater then 75 background goes red. Delete some characters and background goes back to white.
ASKER
Hey what happened to the Message box Code LOL. Did you edit your comment? I was going to try that out also.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BRILLIANT! JUST BRILLIANT! Works like a charm! Just one last thing. What if i wanted to do a 3 color scheme. Like good, warning, maximum. Would I just use ELSE?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I do need it while editing the controls only. After it is saved there is no need for it. It will just set a warning for the user to know while editing. Hopefully to keep character count down.
ASKER
Would there be a way to only see the yellow when the control has the focus and to revert back to White after the control loses focus?
ASKER
Nevermind I got it.
Control Name is SkuNm
Yellow if greater then 75 length with On change Event:
Then to revert back to white after with Lost focus Event:
Control Name is SkuNm
Yellow if greater then 75 length with On change Event:
Private Sub SkuNm_Change()
If Len(SkuNm.Text) > 75 Then
SkuNm.BackColor = vbYellow
Else
SkuNm.BackColor = vbWhite
End If
End Sub
Then to revert back to white after with Lost focus Event:
Private Sub SkuNm_LostFocus()
SkuNm.BackColor = vbWhite
End Sub
ASKER
THANK YOU!