naungsai
01-19-2009, 01:48 AM
Dear Friends
I have a field which need 3 characters.
The first charactor can be "A" or "B" or "C" or "D". (No blank)
The Second charactoer can be "A" or "B" or "C" or blank.
The Third charactoer can be "A" or "B" or "C" or blank.
How should I do it? I prefer more in input mask.
DCrake
01-19-2009, 03:26 AM
If you want to validate this string from more than one location in your application then paste the following function into a module, otherwise paste it in the vba code of your form
Public Function vInput(AnyString As String) As Boolean
If Len(AnyString) > 3 Or Len(AnyString) = 0 Then
vInput = False
Exit Function
End If
If InStr("ABCD", Left(AnyString, 1)) = 0 Then
vInput = False
Exit Function
End If
Dim C As String
For i = 2 To Len(AnyString)
C = Mid(AnyString, i, 1)
If InStr("ABC ", C) = 0 Then
vInput = False
Exit Function
End If
Next
vInput = True
End Function
To use this function
If vInput(Me.TxtField) = False then
MsgBox "Invalid Code Entered"
End If
Where Me.TxtField = the name of your textbox
David
naungsai
01-20-2009, 12:02 AM
If vInput(Me.TxtField) = False then
MsgBox "Invalid Code Entered"
End If
Where Me.TxtField = the name of your textbox
David
Dear DCrake
Thank you. It works.
In the second part, I want to clear the text that I have enter then get the focus on it. Can you please help me again?
Best
DCrake
01-20-2009, 02:59 AM
I am reading that if the response is false then you want to clear the contents of the text box and set the focus back to the text box?
add
Me.TextBox = ""
Me.TextBox.SetFocus
after the msgbox line