Thread
:
limit textbox to blank or exactly 4 numberic digits
View Single Post
#
5
Posted to microsoft.public.excel.programming
tissot.emmanuel
external usenet poster
Posts: 18
limit textbox to blank or exactly 4 numberic digits
Hi,
Private Sub txtbxPhonePost_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < 48 Or KeyAscii 57 Then KeyAscii = 0 'Numeric keys only
End Sub
Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With txtbxPhonePost
If Len(.Text) 0 And Len(.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4 numbers!",
vbOKOnly
.Text = vbNullString'Clear the textbox
Cancel = True'Leave the focus on the textbox
End If
End With
End Sub
Is it ok?
Best regards from France,
Manu/
"Shawn" a écrit dans le message de news:
...
I added this below the message box:
MsgBox "This box must be blank or contain exactly 4 numbers!", vbOKOnly
If VBAOk Then
usfDemo.txtbxPhonePost.Text = ""
usfDemo.txtbxPhonePost.SetFocus
End If
However, the textbx doesn't clear or select?
--
Thanks
Shawn
"Shawn" wrote:
This works
Private Sub txtbxPhonePost_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtbxPhonePost.Value = "" Then
usfDemo.cmbxDOBMonth.SetFocus
Else
If IsNumeric(usfDemo.txtbxPhonePost.Text) = False Then
MsgBox "This box must be blank or contain exactly 4
numbers!",
vbOKOnly
Else
If Len(usfDemo.txtbxPhonePost.Text) < 4 Then
MsgBox "This box must be blank or contain exactly 4
numbers!", vbOKOnly
End If
End If
End If
End Sub
Is there a better way?
--
Thanks
Shawn
Reply With Quote
tissot.emmanuel
View Public Profile
Find all posts by tissot.emmanuel