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
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