B
Bill nguyen
I use the sub below to detect data entry error. The problem is that users
are still able to move out of the textbox AFTER the sub is run (and error
msg popped up) without having to correct the invalid data. In order to trap
all possible movements, I have to run the sub in Key events and Mouse
events. This is a lot of work.
I guess there must be a way to catch all key/mouse in and out the text box
so that we can run validation once and still be able to force the user to
supply valid data before leaving the textbox.
Any help is greatly appreciated.
Bill
--------------------
Private Sub txtBgross1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtBgross1.TextChanged
Dim bValid As Boolean
bValid = ValidateDataEntry(1, Trim(txtBgross1.Text), "BOL Gross")
If bValid = False Then
txtBgross1.Focus()
End If
End Sub
Private Function ValidateDataEntry(ByVal entryType As Integer, _
ByVal entryVal As String, _
ByVal entrySource As String) As Boolean
Dim bAnsw As Boolean = True
Select Case entryType
Case 1
If IsNumeric(entryVal) = False Then
Beep()
MsgBox(entrySource & " must be numeric!", MsgBoxStyle.OKOnly, "Data Entry
Validation")
bAnsw = False
End If
End Select
Return bAnsw
End Function
are still able to move out of the textbox AFTER the sub is run (and error
msg popped up) without having to correct the invalid data. In order to trap
all possible movements, I have to run the sub in Key events and Mouse
events. This is a lot of work.
I guess there must be a way to catch all key/mouse in and out the text box
so that we can run validation once and still be able to force the user to
supply valid data before leaving the textbox.
Any help is greatly appreciated.
Bill
--------------------
Private Sub txtBgross1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtBgross1.TextChanged
Dim bValid As Boolean
bValid = ValidateDataEntry(1, Trim(txtBgross1.Text), "BOL Gross")
If bValid = False Then
txtBgross1.Focus()
End If
End Sub
Private Function ValidateDataEntry(ByVal entryType As Integer, _
ByVal entryVal As String, _
ByVal entrySource As String) As Boolean
Dim bAnsw As Boolean = True
Select Case entryType
Case 1
If IsNumeric(entryVal) = False Then
Beep()
MsgBox(entrySource & " must be numeric!", MsgBoxStyle.OKOnly, "Data Entry
Validation")
bAnsw = False
End If
End Select
Return bAnsw
End Function