MarkK
bit cruncher
- Local time
- Today, 02:18
- Joined
- Mar 17, 2004
- Messages
- 8,570
One thing I do recall arguing in favour of a few times...
• Rather than manage a subset of controls by setting the Tag property in design view, and then enumerating the form's entire controls collection to work with them, do something like...
• I prefer to list the subset's member controls in code so I can see them--and add and remove them immediately.
• Don't have to navigate design view, back and forth, find the control, open a property sheet, select the "Other" tab, and dig around.
• Just type "Me." and select the control by name from intellisense, and stuff it into some kind of enumerable.
I've even just done it like this...
Makes it easy to do stuff like...
And more than half this code (doesn't have to be) (shouldn't be) on every form
• Rather than manage a subset of controls by setting the Tag property in design view, and then enumerating the form's entire controls collection to work with them, do something like...
Code:
Private cts_ As VBA.Collection
Property Get MyCtlSubset() As VBA.Collection
If cts_ Is Nothing Then Set cts_ = GetCollection(Me.cmdButton, Me.Text0, Me.Text2, Me.Text4)
Set MyCtlSubset = cts_
End Property
Private Function GetCollection(ParamArray stuff()) As VBA.Collection
Dim var
Set GetCollection = New VBA.Collection
For Each var In stuff
GetCollection.Add var
Next
End Function
• Don't have to navigate design view, back and forth, find the control, open a property sheet, select the "Other" tab, and dig around.
• Just type "Me." and select the control by name from intellisense, and stuff it into some kind of enumerable.
I've even just done it like this...
Code:
Property Get MyCtrlArray() As Variant
MyCtrlArray = Array(Me.cmdButton, Me.Text0, Me.Text2, Me.Text4)
End Property
Code:
Private Sub Form_Load()
SetCtlSubset_Visible Me.MyAdminButtonSet, Sys.User.IsAdmin
End Sub
Private Sub Form_Current()
SetCtrlSubset_Enabled Me.MyEditOrderButtonSet, IsNull(Me.OrderShipDate)
End Sub
Sub SetCtlSubset_Enabled(vEnumerable As Variant, State As Boolean)
Dim var
For Each var In vEnumerable
var.enabled = State
Next
End Sub
Sub SetCtlSubset_Visible(vEnumerable As Variant, State As Boolean)
Dim var
For Each var In vEnumerable
var.visible = State
Next
End Sub