bradyboyy88
Well-known Member
- Joined
- Feb 25, 2015
- Messages
- 562
I have the following code so far which uses arrays to add click events for newly generated labels. However, I want to convert this to using collections instead since I have to redim preserve everytime a button is made which is supposively a performance hog. I have tried to convert over to collection but passing the event doesnt seem to do anything for the older labels created. So using this code could someone help point me in the right direcftino for correction using collections instead of array. Also, how do I delete these labels dynamically? I need to do that so they dont just keep adding up since the screen it generates on is open most of the day using new queries and such.
module
class module
module
Code:
Option Explicit
Dim DynamicControl() As New DynamicControls
Sub CreateLabelUMD(FRAME As MSForms.FRAME, Label_Caption As String, Top_Position As Integer, Left_Position As Integer, Width_Value As Integer, Visible_Value As Boolean)
Dim Control As MSForms.Label
Set Control = FRAME.Controls.Add("Forms.Label.1", , True)
With Control
.AutoSize = True
.Width = Width_Value
.Caption = Label_Caption
.Left = Left_Position
.Top = Top_Position
.ForeColor = &HFF0000
.Font.Underline = True
.Visible = Visible_Value
End With
ReDim Preserve DynamicControl(1 To i)
Set DynamicControl(i).New_Label = Control
i = i + 1
End Sub
Sub RemoveLabelsUMD(FRAME As MSForms.FRAME)
While i > 0
FRAME.Controls.Remove DynamicControl(i)
i = i - 1
Loop
End Sub
class module
Code:
Option Explicit
Public WithEvents New_Label As MSForms.Label
Public Sub New_Label_Click()
OpenFile New_Label.Caption
End Sub
Last edited: