G
Guest
Hi Everyone,
I got the following code from Deborah Kurata's book. I need to return the
control that matches the name that I pass into the function. It does iterate
through the form but it will not return a control reference. Following the
code, it does actually get a reference, but when it returns from one of the
recursize calls, the code keeps going. For examle:
First call to FinControl
Has child so call FindControl again
Finds control, returns the reference
'Comment I need a garnteed way of exiting now
Keeps looping, and if a control has child again, call FindControl again
Private Function FindControl( ByVal ControlName As String, ByVal CurrentForm
As control) As Control
Dim rtn As Control
For Each ctrl As Control In CurrentForm.Controls
If ctrl.Name = Controlname then
rtn = ctrl
exit For
End If
If ctrl.HasChildren then
FindControl(ControlName, ctrl)
End If
Next ctrl
return rtn
End Function
What is the best way to handle this one. Thanks for any info.
Michael
I got the following code from Deborah Kurata's book. I need to return the
control that matches the name that I pass into the function. It does iterate
through the form but it will not return a control reference. Following the
code, it does actually get a reference, but when it returns from one of the
recursize calls, the code keeps going. For examle:
First call to FinControl
Has child so call FindControl again
Finds control, returns the reference
'Comment I need a garnteed way of exiting now
Keeps looping, and if a control has child again, call FindControl again
Private Function FindControl( ByVal ControlName As String, ByVal CurrentForm
As control) As Control
Dim rtn As Control
For Each ctrl As Control In CurrentForm.Controls
If ctrl.Name = Controlname then
rtn = ctrl
exit For
End If
If ctrl.HasChildren then
FindControl(ControlName, ctrl)
End If
Next ctrl
return rtn
End Function
What is the best way to handle this one. Thanks for any info.
Michael