validation for 10 text boxes

T

TUNGANA KURMA RAJU

1.how to validate a collection of 10 boxes for numbers only.I know code for 1
textbox
like
Private Sub TextBox1_change
If TextBox1= vbNullstring Then Exit Sub .... so..so
what validation code for collection of controls in short will do ?
2. I want validation for a TextBox6 for a number not greater than other
TextBox2 in same userForm.
 
R

Rick Rothstein \(MVP - VB\)

I think you will need to answer a few questions before anyone will be able
to help you out...

1. What do you mean when you say "numbers"... integers only or are floating
point values allowed?

2. When are you attempting to do your "validation"... when the user is
typing into the TextBox itself, or afterwards when all the TextBoxes have
been filled in and an OK button is pressed?

3. In your example labeled #2, did you have something more in mind than
TextBox6.Value < TextBox2.Value?

With respect to my #2 above, I would note that your example show you using a
Change event for you validation which suggests you are trying to validate
the entry as it is being typed in. I would point out that you cannot use
only the Change event by itself to validate values... the user will always
be able to bypass your validation routine by pasting invalid data into the
TextBox.

Rick
 
N

Norman Jones

Hi Tungana,

Your validation requirementa appear
vague.

However, as a starting point, try
somethiing like:


'============>>
Option Explicit

Private Sub CommandButton1_Click()
Dim i As Long
Dim sStr As String

With Me
If .TextBox6.Value <> vbNullString _
And .TextBox2.Value <> vbNullString Then
If CDbl(.TextBox6.Value) > _
CDbl(.TextBox2.Value) Then
'\\ Do something, e.g.:
MsgBox Prompt:="TextBox6 value must " _
& "be lower than TextBox2"
End If
End If

For i = 1 To 10
If .Controls("TextBox" & i).Value = _
vbNullString Then
sStr = sStr _
& .Controls("TextBox" & i).Name _
& vbNewLine
End If
Next i
End With
If Len(sStr) Then
MsgBox Prompt:="The TextBoxes " _
& vbNewLine & sStr _
& " musthave a value inserted"
End If
End Sub
'<<============
 
T

TUNGANA KURMA RAJU

Thanks Rick,
1.numbers means numeric values with 2 decimals
a.leaving the textbox without entering any value,that means blank textboxes
b. for sometext boxes entering a numeric value mandatory.
2.Afterwards ,when all the text boxes filled.
3.I have a calculated textbox value in TextBox2,fetched from a w/sheet.For
example
textBox2 represents "Eligible amount of loan",Textbox6 represents "amount of
loan to be given".Therefore the value in Textbox6 should not be greater than
value in TextBox2.
som
 
T

TUNGANA KURMA RAJU

Thanks Norman,I will check with your code and let you know whether they works
are not.I will reply soon.
 
T

TUNGANA KURMA RAJU

Mr.Norman,
Thanks for your code,but it is not working well.whenever i am putting text
in textbox2,or Text box6 ,error is coming,for debugging.Second part of
question for validation of other textboxes ,if I enters text they are
accepting the text,so validation for numeric numbers is not functioning.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top