Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty and Enabled field problem

Status
Not open for further replies.

myrgir

Programmer
Feb 7, 2006
62
CA
hi I have a form with tabcontrol with 10 tabpage. In it, I have many combo box and textbox. I want to add a validation that when a combobox or a textbox is empty and enabled. Every enabled fields shouldn't be empty. Do here's my function.

Private Function Validation(ByVal Container As Control) As Boolean
Dim valid As Boolean
Dim ctrl As Control
valid = True

'TabPage1

For Each ctrl In Container.Controls
If TypeOf (ctrl) Is ComboBox Or TypeOf (ctrl) Is TextBox Then
If ctrl.Visible = True Then
If ctrl.Text = String.Empty And ctrl.Enabled = True Then
MsgBox("Please enter a value in each field")
valid = False
Exit Function
End If
End If
Else
If ctrl.HasChildren Then Validation(ctrl)
End If
Next
Return valid
End Function


My problem is that if I'm not on a tabpage that has a empty and enabled field, it would put my variable "valid" at true. but if the focus is on the tabpage that has empty and enabled field, it would display the error message.

What is wrong with my function?
Thanks in advance
 
it probably has nothing to do with the function but rather with the buggy tabpage/control. if a tabpage has never been clicked on it never gets drawn or created wherefor the controls on it have not been instantiated so they can't be referenced. One way of hacking this is to do a tabpage.show before you try to iterate thru its controlcollection.

Christiaan Baes
Belgium

"My new site" - Me
 
Hi
A little bit late but...Unfortunaly, it doesn't work.
Do you have any other idea?
Thanks
 
still have that problem
Can somebody help me please..
I need to finish it for tomorrow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top