Looping through specific controls on a form

E

Eric.I.Feurich

Dear all,
I'm trying to validate if information has been added in to textboxes and
combo boxes.
Private Function CheckValues() As Boolean
'**************************************************
'***
'*** Function : CheckValues()
'*** Purpose : Check if all values as filled -in
'***
'***
'***
'****************************************************
Dim frmMain As New frmMain '*** Instance of the Main form
Dim ctrl As New Control '*** Instance of the systems control object
With frmMain
For Each ctrl In .Controls
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Then
If ctrl.Text = "" Then
CheckValues = False
Exit Function
End If
End If
Next
CheckValues = True
End With
End Function

This is what i have so far. But when in the function the ctrl.text property
is empty when in the form there is tekst in the control.
Is this because i am using an instance of the frmmain form ??
If i don't instanciate the frmmain form i can't acces the properties.

Does anyone know an answer on this??

GreetZ,

Eric
 
J

Jeremy Cowles

Eric.I.Feurich said:
Dear all,
I'm trying to validate if information has been added in to textboxes and
combo boxes.
Private Function CheckValues() As Boolean
'**************************************************
'***
'*** Function : CheckValues()
'*** Purpose : Check if all values as filled -in
'***
'***
'***
'****************************************************
Dim frmMain As New frmMain '*** Instance of the Main form
Dim ctrl As New Control '*** Instance of the systems control object
With frmMain
For Each ctrl In .Controls
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Then
If ctrl.Text = "" Then
CheckValues = False
Exit Function
End If
End If
Next
CheckValues = True
End With
End Function

This is what i have so far. But when in the function the ctrl.text property
is empty when in the form there is tekst in the control.
Is this because i am using an instance of the frmmain form ??
If i don't instanciate the frmmain form i can't acces the properties.

I cant fully understand what you have written. Perhaps your problem is that
you are getting a value of Nothing from the text property and this is
causing an error. Try this:

If ctrl.Text Is Nothing OrElse ctrl.Text = "" Then
...
End If


HTH,
Jeremy
 
A

Armin Zingler

Eric.I.Feurich said:
Dear all,
I'm trying to validate if information has been added in to textboxes
and combo boxes.
Private Function CheckValues() As Boolean
'**************************************************
'***
'*** Function : CheckValues()
'*** Purpose : Check if all values as filled -in
'***
'***
'***
'****************************************************
Dim frmMain As New frmMain '*** Instance of the Main form
Dim ctrl As New Control '*** Instance of the systems control
object With frmMain
For Each ctrl In .Controls
If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox Then
If ctrl.Text = "" Then
CheckValues = False
Exit Function
End If
End If
Next
CheckValues = True
End With
End Function

This is what i have so far. But when in the function the ctrl.text
property is empty when in the form there is tekst in the control.



Sorry, I don't understand the last sentence.
Is this because i am using an instance of the frmmain form ??

What else should you use? Of course you must use an instance of frmMain.
If i don't instanciate the frmmain form i can't acces the
properties.
Right

Does anyone know an answer on this??

I don't see the point. If you don't have a form, there are no textboxes or
comboboxes to check.
 

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