Operon
07-21-2016, 11:03 AM
I have a userform in PowerPoint 2016 that contains several textboxes and I'd like to identify those whose contents have been edited since the last save. To this end I created a test scenario whereby a userform has two text boxes and a commandbutton that prints the contents of a collection which is created when these textboxes have undergone change events. More specifically, my thinking is to parse through all the objects on the userform identifying the textboxes and assigning to the textbox's change event a class module that compiles the textbox's name and an associated boolean as an object into a collection. This collection then can be used to identity those objects (textboxes) and resets them.
This code creates the class module, mkTextBox that will be initiated within the class module clsTextBox which is used to enumerate these textboxes:
Public TName As String
Public TFlag As Boolean
Public Function State_TB(ByVal T_Name As String, ByVal T_Flag As Boolean)
TName = T_Name
TFlag = T_Flag
End Function
This class module clsTextBox, which is invoked upon the textbox's change event, assigns the object MT_TB with the attributes of mkTextBox and then adds the object as MT_TB to the collection TBList:
Public TBList As New Collection
Private WithEvents MyTextBox As MSForms.TextBox
Public Property Set Control(tb As MSForms.TextBox)
Set MyTextBox = tb
End Property
Public Sub MyTextBox_Change()
Set MT_TB = New mkTextBox
MT_TB.State_TB MyTextBox.Name, True
TBList.Add MT_TB
Debug.Print MT_TB.TName, MT_TB.TFlag, TBList.Count
End Sub
This code, upon he userform load event, parses through the userform and creates a collection as tbCollection of all the textboxes on the userform. It aslo assigns the class module clsTextBox to these textboxes:
Public ctrl As MSForms.Control
Dim tbCollection As Collection
Public MT_TB As mkTextBox
Private Sub UserForm_Initialize()
Dim ctrl As MSForms.Control
Dim obj As clsTextBox
Set TBList = New Collection
Set tbCollection = New Collection
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
Set obj = New clsTextBox
Set obj.Control = ctrl
tbCollection.Add obj
End If
Next ctrl
Set obj = Nothing
End Sub
This code assigns to a commandbutton instructions that lists the contents of the collection TBList:
Private Sub CommandButton1_Click()
For Each MT_TB In TBList
Debug.Print MT_TB.TName
Next
End Sub
This code doesn't through off any errors but the:
1. command button doesn't work.
2. Also the TBList collection's count resets itself each time a change event upon moving to another textbox of the userform. I know why; the clsTextBox class module reforms the collection each time the statement:
Public TBList As New Collection is processed. However moving the statement:
Public TBList As New Collection
anywhere else in the code causes an error when MT_TM is attempted to be added to TBList.
I'm not sure why I can't get this to work as intended. any assistance is gratefully appreciated.
This code creates the class module, mkTextBox that will be initiated within the class module clsTextBox which is used to enumerate these textboxes:
Public TName As String
Public TFlag As Boolean
Public Function State_TB(ByVal T_Name As String, ByVal T_Flag As Boolean)
TName = T_Name
TFlag = T_Flag
End Function
This class module clsTextBox, which is invoked upon the textbox's change event, assigns the object MT_TB with the attributes of mkTextBox and then adds the object as MT_TB to the collection TBList:
Public TBList As New Collection
Private WithEvents MyTextBox As MSForms.TextBox
Public Property Set Control(tb As MSForms.TextBox)
Set MyTextBox = tb
End Property
Public Sub MyTextBox_Change()
Set MT_TB = New mkTextBox
MT_TB.State_TB MyTextBox.Name, True
TBList.Add MT_TB
Debug.Print MT_TB.TName, MT_TB.TFlag, TBList.Count
End Sub
This code, upon he userform load event, parses through the userform and creates a collection as tbCollection of all the textboxes on the userform. It aslo assigns the class module clsTextBox to these textboxes:
Public ctrl As MSForms.Control
Dim tbCollection As Collection
Public MT_TB As mkTextBox
Private Sub UserForm_Initialize()
Dim ctrl As MSForms.Control
Dim obj As clsTextBox
Set TBList = New Collection
Set tbCollection = New Collection
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
Set obj = New clsTextBox
Set obj.Control = ctrl
tbCollection.Add obj
End If
Next ctrl
Set obj = Nothing
End Sub
This code assigns to a commandbutton instructions that lists the contents of the collection TBList:
Private Sub CommandButton1_Click()
For Each MT_TB In TBList
Debug.Print MT_TB.TName
Next
End Sub
This code doesn't through off any errors but the:
1. command button doesn't work.
2. Also the TBList collection's count resets itself each time a change event upon moving to another textbox of the userform. I know why; the clsTextBox class module reforms the collection each time the statement:
Public TBList As New Collection is processed. However moving the statement:
Public TBList As New Collection
anywhere else in the code causes an error when MT_TM is attempted to be added to TBList.
I'm not sure why I can't get this to work as intended. any assistance is gratefully appreciated.