'usercontrol module
Public ParentForm As Form
Public ParentControlName As String
'usercontrol code example
Option Explicit
'Default Property Values:
Const m_def_LinkIndex = -1
Const m_def_LinkName = 0
'Property Variables:
Dim m_LinkIndex As Integer
Dim m_LinkName As Variant
Private Sub Command1_Click()
If LinkIndex <> -1 Then
UserControl.Parent.Controls(LinkIndex).Text = "weqweqweqe"
End If
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Set ParentForm = UserControl.Parent
ParentControlName = UserControl.Extender.Name
m_LinkName = PropBag.ReadProperty("LinkName", m_def_LinkName)
m_LinkIndex = PropBag.ReadProperty("LinkIndex", m_def_LinkIndex)
End Sub
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=14,0,0,0
Public Property Get LinkName() As Variant
LinkName = m_LinkName
End Property
Public Property Let LinkName(ByVal New_LinkName As Variant)
m_LinkName = New_LinkName
PropertyChanged "LinkName"
End Property
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
m_LinkName = m_def_LinkName
m_LinkIndex = m_def_LinkIndex
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("LinkName", m_LinkName, m_def_LinkName)
Call PropBag.WriteProperty("LinkIndex", m_LinkIndex, m_def_LinkIndex)
End Sub
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=7,0,0,-1
Public Property Get LinkIndex() As Integer
LinkIndex = m_LinkIndex
End Property
Public Property Let LinkIndex(ByVal New_LinkIndex As Integer)
m_LinkIndex = New_LinkIndex
PropertyChanged "LinkIndex"
End Property
'in the property Page
Option Explicit
Private Sub List1_Click()
Changed = True
End Sub
Private Sub PropertyPage_Initialize()
On Error GoTo ErrorTrap
Dim c As Control
Dim index As Integer
Dim Count As Integer
List1.Clear
For Each c In ParentForm.Controls 'this variable is set in the usercontrol
Count = Count + 1
'make sure the control isn't the usercontrol but is a textbox
If c.Name <> ParentControlName And TypeOf c Is TextBox Then
'ParentControlName is set in UC
index = -1
index = c.index ' part of an array, set to index else after err, index=-1
If index = -1 Then
'control is not part of an array
List1.AddItem c.Name
List1.ItemData(List1.NewIndex) = Count
Else
'control is part on an array
List1.AddItem c.Name & "(" & index & ")"
List1.ItemData(List1.NewIndex) = Count
End If
End If
Next c
Exit Sub
ErrorTrap:
Resume Next
End Sub
Private Sub PropertyPage_ApplyChanges()
SelectedControls(0).LinkName = List1.Text 'this is for show
SelectedControls(0).LinkIndex = List1.ItemData(List1.ListIndex) - 1 'this is the actual link
End Sub