-
Aquiring new knownledge about creating controls at run time, I would like to them to share a common event-procedure.
Does anyone know how to do this? Look at my pseudo to see what I'm looking for.
Code:
Dim myControls(100) As objects
Sub MakeTheControls()
Set myControls(0) = Controls.Add(...)
Set myControls(1) = Controls.Add(...)
...
End Sub
Sub CommonEvent(AString As String)
'AString is an identifier that i can use in the following:
Select Case AString
Case "my1stcontrol": ...
Case "my2ndcontrol": ...
...
End Select
End Sub
-
What you're talking about is a control array. Control arrays share the same event procedure:
Sub Control_Click(Index as Integer)
'Test for which control was clicked by its index
End Sub
I beleive that you have to add 1 control at design time and then use the 'Load' statement at run time. I don't have a good example to show you, but I know it's on my computer somewhere. If I find it, I'll email it to you.
Hope this helps,
Dan
-
Here's an example. Make a Contrtol called MyControl and place the following code into a CommandButton. Make sure that the Index property to MyControl is set to 0.
Code:
Load MyControl(1)
MyControl(1).Move 0, 0
MyControl(I).Visible = True
-
You don't by any way know how to create an control array in VBA, do you? You can't do it the way you do it in VB5/6. If you can at all.
-
No, I don't think that method would work in VBA.