Try this. It's not terribly elegant, but I think
it will get the job done.
------------------
'call with the name of the control you're looking for
If ControlIsThere( "MyBigGiantText Box") Then...
'You need this to be available in both the
'function and the recursive routine that
'it calls, so you have something to stop
'the recursion. I'd make it a form-level
'variable.
Dim FoundControl as Boolean
Private Function ControlIsThere( controlName as String) as Boolean
'Set this to false.
FoundControl = False
'Call the recursive routine with the form.
ControlExists(M e)
'Return the result.
Return FoundControl
End Function
'This will recurse, so it gets all the controls on the form.
'This way, if you have panels, for example, it will
' touch the controls inside those containers.
Private Sub ControlExists(B yVal ctrlContainer As Control)
For Each ctrl As Control In ctrlContainer.C ontrols
'Debug.Print(ct rl.Name.ToStrin g)
If ctrl.Name = "MyBigGiantText Box" Then
FoundControl = True
Exit For
End If
'if control has children, call this function recursively
If ctrl.HasChildre n Then
ControlExists(c trl)
End If
Next
End Sub
Robin S.
"Darin" <darin_nospam@n ospameverwrote in message
news:e6******** ******@TK2MSFTN GP02.phx.gbl...
>I have a form that might (or might not) have a textbox on it named
something particular - how can I find if the form has the control, and
if it does what the text of the control has? This form has textboxes
that are created on the fly, and when the OK is clicked I need to figure
out which ones are on the screen and what the text is in each to do
other stuff.
So, kind of like:
dim xstr as string
xstr=me.findcon trol("tText").t ostring
Thanks.
Darin
*** Sent via Developersdex http://www.developersdex.com ***