Re: Required Field for 7 Numeric digits only



What if they type in 7 letters?

Rick


"JLGWhiz" <JLGWhiz@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:C5DB53F4-3F03-411D-8375-9D490510B47F@xxxxxxxxxxxxxxxx
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: 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 To Use The Number Part Of A TextBox Name As A Variable
    ... You don't need to know how many digits ... Private Sub tbx_Change ... The same demo shows how to process any textbox only by supplying its number ... Private Sub TextBox1_Enter' similar ...
    (microsoft.public.excel.programming)
  • RE: Required Field for 7 Numeric digits only
    ... more then 7 and will continue onto the next textbox. ... Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) ... MsgBox "Please enter Accounting Unit Code (7 Digits)" ...
    (microsoft.public.excel.programming)

Loading