validate controls

T

tkaplan

i have an excel form that i want that after the user enters data, whe
he tries to exit text box it validates the data for him and if it'
valid the background changes to white.
i currently have the colors changing if there is any data in the txtbo
at all. i would like it to be that it needs to have two names in th
field - the director's first and last name. so i want it to check th
the first word is more than one letter, followed by a space, and the
at least two more letters.

i am putting the code in the txtDirector_Exit event.
i know the changing color code, i need to code to check the data in th
box.

thanks in advance
tkapla
 
R

Rowan

Maybe like this.

Private Sub txt_Director_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim spac As Integer
Dim vld As Boolean
spac = InStr(1, txt_Director.Value, " ")
If spac < 3 Then
vld = False
ElseIf spac > Len(txt_Director.Value) - 2 Then
vld = False
Else
vld = True
End If
If Not vld Then
Me.txt_Director.BackColor = vbBlue
End If
End Sub

Hope this helps
Rowan
 
D

Dave Peterson

You have another reply to your post in .misc
i have an excel form that i want that after the user enters data, when
he tries to exit text box it validates the data for him and if it's
valid the background changes to white.
i currently have the colors changing if there is any data in the txtbox
at all. i would like it to be that it needs to have two names in the
field - the director's first and last name. so i want it to check the
the first word is more than one letter, followed by a space, and then
at least two more letters.

i am putting the code in the txtDirector_Exit event.
i know the changing color code, i need to code to check the data in the
box.

thanks in advance
tkaplan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top