vba_monkey
Board Regular
- Joined
- Dec 18, 2013
- Messages
- 112
Hello,
I am trying to validate entries into a userform field to check that it only contains numbers and is 7 digits long. All i need it to do is highlight the field in red if the entry is not correct but not if the field is exited without entering anything. This is what I have so far:
The results from this are:
If non numeric characters are included the field turns red, which is correct.
If a number less than or more than 7 digits is entered the field stays white, which is wrong.
If the field is activated but then exited without entering anything the field turns red, which is wrong.
Any ideas please?
I am trying to validate entries into a userform field to check that it only contains numbers and is 7 digits long. All i need it to do is highlight the field in red if the entry is not correct but not if the field is exited without entering anything. This is what I have so far:
Code:
Private Sub SJNKE_Policy_1_TB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(SJNKE_Policy_1_TB.Text) And Len(SJNKE_Policy_1_TB.Text) <> 7 Or SJNKE_Policy_1_TB.Text <> "" Then
SJNKE_Policy_1_TB.BackColor = &HFF&
Else
SJNKE_Policy_1_TB.BackColor = &H80000005
End If
End Sub
The results from this are:
If non numeric characters are included the field turns red, which is correct.
If a number less than or more than 7 digits is entered the field stays white, which is wrong.
If the field is activated but then exited without entering anything the field turns red, which is wrong.
Any ideas please?