G
Guest
Hi, everyone,
I have developed a Function to check the input TxtBox in order to prevent
user from inputing incorrect data. The TxtBox is to receive 7 digits in
String type. My problem is if I put this Function in the BeforeUpdate of the
TxtBox, I will encounter an erro message saying that I can not store
something in it. If I put this in the AfterUpdate of the TxtBox, everything
is fine except the cursor will jump to the next TxtBox after the error
message. That is, in this case I'd like to let the cursor stay in place to
let the user key in the correct data. Can anyone help me solve this problem?
Thank you.
Public Function (strData As String) As String
If Nz(strData, "") = "" Or strData = "" Then
Exit Function
ElseIf strData Like "*[!0-9]*" Then
MsgBox "You must key in 0 to 9"
Exit Function
ElseIf Len(strData) > 7 Then
MsgBox "You key in more than 7 digits"
Exit Function
ElseIf Len(strData) < 7 Then
strData = Format(strData, "0000000")
ValidData = strData
End If
End Function
I have developed a Function to check the input TxtBox in order to prevent
user from inputing incorrect data. The TxtBox is to receive 7 digits in
String type. My problem is if I put this Function in the BeforeUpdate of the
TxtBox, I will encounter an erro message saying that I can not store
something in it. If I put this in the AfterUpdate of the TxtBox, everything
is fine except the cursor will jump to the next TxtBox after the error
message. That is, in this case I'd like to let the cursor stay in place to
let the user key in the correct data. Can anyone help me solve this problem?
Thank you.
Public Function (strData As String) As String
If Nz(strData, "") = "" Or strData = "" Then
Exit Function
ElseIf strData Like "*[!0-9]*" Then
MsgBox "You must key in 0 to 9"
Exit Function
ElseIf Len(strData) > 7 Then
MsgBox "You key in more than 7 digits"
Exit Function
ElseIf Len(strData) < 7 Then
strData = Format(strData, "0000000")
ValidData = strData
End If
End Function