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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CONTROL ARRAYS AND TYPENAME 1

Status
Not open for further replies.

gismo

Technical User
Jul 24, 2002
35
US
I'm trying to distinguish between textboxes that are in control arrays and those that aren't in control arrays on a form. If Text1 is not a control array and Text2 is a control array I can do
Code:
Dim ControlType1 as string
Dim ControlType2 as string
ControlType1 = TypeName(Text1)
ControlType2 = TypeName(Text2)
ControlType1 will have the value "TextBox" and ControlType2 will have the value "Object" . This is great and the results that I want but since I have many TextBox's to process so I wanted to do:
Code:
Dim ControlType As String
Dim MyControl as Control
For Each MyControl In Form1
ControlType = TypeName(MyControl)
if ControlType = "Object"
   Do something here
End If
Next MyControl
The problem is when I process the textbox control arrays in the for each loop, instead of TypeName returning "Object" it returns "TextBox" just like the TextBox's that aren't in a control array. Is there another way to do this?





 
I'll hope this will be a little help

Private Sub Form_Load()
Dim MyControl As Control
Dim MyObjectName As String
For Each MyControl In Form1
On Error GoTo Errorhandler
MyObjectName = MyControl.Name & "(" & MyControl.Index & ")"
On Error GoTo 0
MsgBox MyObjectName
Next MyControl
Exit Sub
Errorhandler:
MyObjectName = MyControl.Name
Resume Next
End Sub


peterguhl@yahoo.de
 
Private Sub Form_Load()

'''Label1.ToolTipText = "My Program" & vbCrLf & "(68% complete)" & vbNullChar
'''Text1(1).ToolTipText = "My Program" & vbCrLf & "(68% complete)" & vbNullChar
'''MsgBox DateDiff("m", #1/1/2002#, #3/31/2002# + 1)

Dim MyControl As Control
Dim MyObjectName As String
Dim test As String
For Each MyControl In Form1
On Error GoTo Errorhandler
MyObjectName = MyControl.Name & "(" & MyControl.Index & ")"
On Error GoTo 0
test = test & Chr(13) & TypeName(MyControl) & Chr(9) & MyObjectName
Next MyControl
MsgBox test
Exit Sub
Errorhandler:
MyObjectName = MyControl.Name
Resume Next
End Sub


peterguhl@yahoo.de
 
Thanks Peter, it works great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top