Field Validation.

  • Thread starter Thread starter sigh
  • Start date Start date
S

sigh

HI,
I would like to check for my input fields to make sure
the Data input correctely.
Example. I the text box content 4 fields. The first one
have to be a Character and the Second one have to be a
numeric and third one have to be a space and the forth one
have to be a numeric. How do I write the VB code to
Validation these?
I would like to put the ccode in the Keypress Event, so
when I key in the wrong data .It will promtp me right away.
Eg. The Right data is R1R 4
Any help would be very appreciated.
 
sigh said:
I would like to check for my input fields to make sure
the Data input correctely.
Example. I the text box content 4 fields. The first one
have to be a Character and the Second one have to be a
numeric and third one have to be a space and the forth one
have to be a numeric. How do I write the VB code to
Validation these?
I would like to put the ccode in the Keypress Event, so
when I key in the wrong data .It will promtp me right away.
Eg. The Right data is R1R 4


Not sure I followed that, but you can use the Like operator
to check for letters and numbers:

If Me.thetextbox Like "[a-z]#[a-z]#" Then
' its ok
Else
' not ok
End If

So if you want to check for errors as the data is entered,
then you could use code along these lines in the Change
event:

Select Case Len(Me.thetextbox.Text)
Case 0
Case 1
If Not Me.thetextbox.Text Like "[a-z]" Then
ErrMsg . . .
End If
Case 2
If Not Me.thetextbox.Text Like "[a-z]#" Then
ErrMsg . . .
End If
Case 3
If Not Me.thetextbox.Text Like "[a-z]#[a-z]" Then
ErrMsg . . .
End If
Case 4
If Not Me.thetextbox.Text Like "[a-z]#[a-z]#" Then
ErrMsg . . .
End If
Case Else
ErrMsg . . .
End Select
 
Back
Top