trouble with control collection
why won't this work:
VB Code:
dim coll as collection
dim og as OptionButton
dim cb as ComboBox
dim TB as TextBox
for each og in me.controls
coll.add og
next
for each.... ' same with textboxes and comboboxes
but it gives me an error.
even this won't work:
for each cb in me.controls
....
ctr.enabled=false
next cb
Re: trouble with control collection
The For Each statement enumerates every item in the collection, not those of a specific type. A variable declared as a specific type can only be set to an instance of that type. Use the generic Control object type and then check for the "type of" control
VB Code:
Dim oCtl as Control
For each oCtl in Me.Controls
oCtl.Enabled = False 'assumes all controls have an enabled property.
If Typeof oCtl is OptionButton then
oCtl.Value = False
ElseIf Typeof oCtl is TextBox then
oCtl.Text = ""
End If
Next
Re: trouble with control collection
And when you want to use a collection you have to create the object and not just define it so you eaither have to do
VB Code:
Dim coll As [HL="#FFFF80"]New [/HL]Collection
coll.Add "something"
or
VB Code:
Dim coll As Collection
Set coll = New Collection
coll.Add "something"
Re: trouble with control collection
thanks... i was thinking along those lines - but i was hoping that VB had a .type property, rather than a TypeOf method (sorta like C)
guess i was wrong
hope it works - thanks