RE: Required Field for 7 Numeric digits only
- From: LRay67 <LRay67@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Mar 2008 12:19:00 -0700
I inserted the If Len(TextBox1.Text) <> 7 Then - below the first
TextBox1.Activate code. It does show me the message that I inserted for the
field to contain only 7 digits. But it does not stop the user from entering
more then 7 and will continue onto the next textbox. I even tried without my
code, just inserting what you gave me with the lostfocus. I would like to
keep all code pertaining to TextBox1 in the same area. Any Suggestions??
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = vbKeyTab Then
If TextBox1 = "" Then
MsgBox "Please enter Accounting Unit Code (7 Digits)"
Application.SendKeys ("{BS}")
TextBox1.Activate
If Len(TextBox1.Text) <> 7 Then
MsgBox "Accounting Unit Code must contain only 7 Digits"
Application.SendKeys ("{BS}")
TextBox1.Activate
End If
Exit Sub
End If
KeyAscii = 0
TextBox3.Activate
End If
End Sub
"JLGWhiz" wrote:
Right click your TextBox1>View Code then paste the snippet below in behind.
the TextBox control. It should then reactivate the text box if someone
closes it with less than seven digits entered.
Private Sub TextBox1_LostFocus()
If Len(TextBox1.Text) <> 7 Then
TextBox1.Activate
End If
End Sub
"LRay67" wrote:
I didn't have my current code when I posed this question. Below is the code
we are using for this particular textbox. I would like the user to be able
to enter data into the field and upon tabbing or leaving the field verify
that they have 7 numeric digits entered (nothing more or less than that). We
have a message stating that they have to enter if nothing is filled
in.......Any suggestions
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = vbKeyTab Then
If TextBox1 = "" Then
MsgBox "Please enter Accounting Unit Code (7 Digits)"
Application.SendKeys ("{BS}")
TextBox1.Activate
Exit Sub
End If
KeyAscii = 0
TextBox3.Activate
End If
End Sub
"JLGWhiz" wrote:
This should cover it all, needed to make the loop so they have to respond.
RETRY:
UserInput = Application.InputBox("Enter an seven numeric digits", _
"NUMERIC ONLY", Type:=1)
If UserInput = "" Or UserInput = False Or Len(UserInput) <> 7 Then
MsgBox "You must enter numbers only."
GoTo RETRY:
End If
"LRay67" wrote:
I have a required field that can contain only 7 numeric digits within the
textbox. Also want to put in a message box to alert them that this field
must have 7 numeric digits. Any suggestions on how to write the code behind
this? Thanks
Linda
- Follow-Ups:
- RE: Required Field for 7 Numeric digits only
- From: JLGWhiz
- RE: Required Field for 7 Numeric digits only
- References:
- Required Field for 7 Numeric digits only
- From: LRay67
- RE: Required Field for 7 Numeric digits only
- From: JLGWhiz
- RE: Required Field for 7 Numeric digits only
- From: LRay67
- RE: Required Field for 7 Numeric digits only
- From: JLGWhiz
- Required Field for 7 Numeric digits only
- Prev by Date: RE: Required Field for 7 Numeric digits only
- Next by Date: RE: Required Field for 7 Numeric digits only
- Previous by thread: RE: Required Field for 7 Numeric digits only
- Next by thread: RE: Required Field for 7 Numeric digits only
- Index(es):
Relevant Pages
|