Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation for 10 text boxes
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation for 10 text boxes
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 "TUNGANA KURMA RAJU" wrote in message ... 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. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation for 10 text boxes
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 '<<============ --- Regards. Norman "TUNGANA KURMA RAJU" wrote in message ... 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. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation for 10 text boxes
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 "Rick Rothstein (MVP - VB)" wrote: 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 "TUNGANA KURMA RAJU" wrote in message ... 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. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation for 10 text boxes
Thanks Norman,I will check with your code and let you know whether they works
are not.I will reply soon. "Norman Jones" wrote: 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 '<<============ --- Regards. Norman "TUNGANA KURMA RAJU" wrote in message ... 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. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
validation for 10 text boxes
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. "Norman Jones" wrote: 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 '<<============ --- Regards. Norman "TUNGANA KURMA RAJU" wrote in message ... 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Validation drop-down boxes | Excel Worksheet Functions | |||
User Form Text Boxes - Copy format of text boxes | Excel Discussion (Misc queries) | |||
Data validation boxes, outputting a final number from the boxes | Excel Discussion (Misc queries) | |||
validation list boxes | Excel Programming | |||
Dynamic Comments/Validation/Text Boxes | Excel Programming |