RE: Required Field for 7 Numeric digits only

Tech-Archive recommends: Fix windows errors by optimizing your registry



You wanted a message in that, didn't you?

Private Sub TextBox1_LostFocus()
If Len(TextBox1.Text) <> 7 Then
MsgBox "Please Edit Your Entry, Seven Digits Needed"
TextBox1.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
.



Relevant Pages

  • RE: TextBox Focus And Active Cursor Movement In User Forms
    ... HOWEVER, if I render the error message ON THE FORM, and not use MsgBox, it's ... Private Sub txtTotalUnits_Exit(ByVal Cancel As MSForms.ReturnBoolean) ... the textbox, and return the blinking cursor to that same textbox... ...
    (microsoft.public.excel.programming)
  • Re: Required Field for 7 Numeric digits only
    ... If the user attempts to leave the TextBox where there are not 7 digits in it, the user will get a MessageBox and then be returned to the TextBox to correct their entry. ... Static SecondTime As Boolean ... Private Sub TextBox1_MouseDown(ByVal Button As Integer, ...
    (microsoft.public.excel.programming)
  • Re: Required Field for 7 Numeric digits only
    ... current code for the textbox that I need to only allow 7 numeric digits. ... Private Sub TextBox1_KeyPress ... CommandButton to accept the entry (and then proceed with the rest of your ... You could test the TextBox while it it being typed into and only make the ...
    (microsoft.public.excel.programming)
  • Re: Format a textbox
    ... would like it to auto format 04/01/09. ... However when I change that to specifically refer to the textbox ... 13 to limit the number of digits after the hypen to 4. ... Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ...
    (microsoft.public.excel.programming)
  • Re: How do I get intl settings out of control panel?
    ... As for a numeric input box that only accepts digits and the decimal ... Dim MaxWhole As Long ... Private Sub Text1_Change ...
    (microsoft.public.vb.general.discussion)