RE: Required Field for 7 Numeric digits only



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: Help with odd type mismatch error
    ... > The only thing I can think of is that the textbox isn't numeric, ... > Private Sub txtLowPercent_KeyPress(ByVal KeyAscii As ... >> Application level function that replaces the worksheet function ...
    (microsoft.public.excel.programming)
  • 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
    ... Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) ... Dim IsValid As Boolean ... ' Checking if TextBox value is 7 digits and all the contents are numeric ...
    (microsoft.public.excel.programming)
  • Re: Selection based on partial input
    ... > I need to enable the user to input the beginning of a name in the> textbox, ... > and, as each new typed character comes in, I want the listbox to> display ... Dim TextArray() As String ... Private Sub UserForm_Initialize ...
    (microsoft.public.excel.programming)
  • Re: excel VBA text
    ... The routines work quite well and protects the TextBox from pasting non-numeric entries as well as stopping non-numeric keypresses. ... Dim LastPosition As Long ... Static SecondTime As Boolean ... Private Sub TextBox1_MouseDown(ByVal Button As Integer, ...
    (microsoft.public.excel.programming)

Loading