Require 8 (specific) characters in a text box

Talismanic

Registered User.
Local time
Today, 23:08
Joined
May 25, 2000
Messages
377
This is a add on to my brain teaser, I can make sure that something is entered into the text box with this:

If IsNull(CodePick) Then
strEval = MsgBox("You must include a value", vbOKOnly, "Entry Error")
Exit Sub
Else

Now is it posible to limit the entry characters to only B, H, X, D, and T. I also want to make sure that at least 8 characters entered.
 
If Len(Me.txtYourInfo) < 8 Then MsgBox("You need at least 8 letters.",,"Invalid Entry")

For i = 1 To Len(Me.txtYourInfo)
Select Case Mid(Me.txtYourInfo,i,1)
Case B, H, X, D, T
Case Else
MsgBox("You must have only a B,H,X,D or T as letters.",,"Invalid Entry")
End Select
Next i
 
Thank You that worked great. Although I think I am going to need to do something on the key press event so that I can catch the characters as they are entered.

Here is what I did with the code you give me:

If IsNull(CodePick) Then
strEval = MsgBox("You must include a value", vbOKOnly, "Entry Error")
Exit Sub
ElseIf Len(Me.CodePick) < 8 Then
strEval = MsgBox("You must include at least 8 characters.", _
vbOKOnly, "Entry Error")
Else
 
Now on the Keypress I tried this:

Private Sub CodePick_KeyPress(KeyAscii As Integer)

If (KeyAscii <> Asc("H") Or KeyAscii <> Asc("D") Or _
KeyAscii <> Asc("X") Or KeyAscii <> Asc("B") _
Or KeyAscii <> Asc("T")) Then KeyAscii = 0
End Sub

But that doesn't let any keys into the text box because of the <>. If I change the <> to = like this:

Private Sub CodePick_KeyPress(KeyAscii As Integer)

If (KeyAscii = Asc("H") Or KeyAscii = Asc("D") Or _
KeyAscii = Asc("X") Or KeyAscii = Asc("B") _
Or KeyAscii = Asc("T")) Then KeyAscii = 0
End Sub

Every key can be entered except the ones listed. How do I limit the letters that can be pressed to the 5 I have listed?
 
Private Sub CodePick_KeyPress(KeyAscii As Integer)
If (KeyAscii = Asc("H") Or KeyAscii = Asc("D") Or _
KeyAscii = Asc("X") Or KeyAscii = Asc("B") _
Or KeyAscii = Asc("T")) Then
Else
KeyAscii = 0
End If
End Sub

HTH,

Ken Grubb
Burlington, NC, USA


[This message has been edited by Ken Grubb (edited 08-07-2001).]
 
Ken,

I think I will file that under, "Doh, Why didn't I think of that?"
wink.gif


I did have to modify it slightly to force upper case letters into the field like this:

KeyAscii = Asc(UCase(Chr$(KeyAscii)))

If (KeyAscii = Asc("H") Or KeyAscii = Asc("D") Or KeyAscii = _
Asc("X") Or KeyAscii = Asc("B") Or KeyAscii = Asc("T")) Then
Else
KeyAscii = 0
End If
 

Users who are viewing this thread

Back
Top Bottom