I'm using Access 2010 and I'm trying to group controls so that I can edit each control's properties in a group as one. I am currently using the control's tag property to specify which group it is apart of and then I loop through call the controls and add it to a collection (through a class module) based on its tag property. However, this means that if I want to add a group to the form, I have to edit my code to reference another instance of my class module and then test for the new group. Is there a way to make it so that my code could be more universal instead of having to duplicate my code for each form and then edit the code to fit the number of groups on that form? I'm thinking it would need a loop, but I don't know what to loop through. Here is what I'm using now.
Code:
Private Sub Form_Load() On Error GoTo Error_Handler Dim ctl As Control Dim Area8 As clsControl Dim Area9 As clsControl Dim Area10 As clsControl Dim db As DAO.Database Dim rst As DAO.Recordset Dim strCriteria As String Set Area8 = New clsControl Set Area9 = New clsControl Set Area10 = New clsControl Set db = CurrentDb Set rst = db.OpenRecordset("qryUserPermissions") For Each ctl In Me.Controls Select Case ctl.ControlType Case acComboBox, acTextBox, acCommandButton If ctl.Properties("Tag") = "Open" Or ctl.Properties("Tag") = "" Then ctl.Properties("Locked") = False ctl.Properties("Visible") = True Else Select Case ctl.Properties("Tag") Case 8 Area8.AddControl ctl, ctl.Name Case 9 Area9.AddControl ctl, ctl.Name Case 10 Area10.AddControl ctl, ctl.Name End Select End If End Select Next ctl With rst strCriteria = "AreaID_fk = 8" .FindFirst strCriteria Area8.Permissions !MaxOfPermissionLevel strCriteria = "AreaID_fk = 9" .FindFirst strCriteria Area9.Permissions !MaxOfPermissionLevel strCriteria = "AreaID_fk = 10" .FindFirst strCriteria Area10.Permissions !MaxOfPermissionLevel End With Exit_Procedure: Set Area8 = Nothing Set Area9 = Nothing Set Area10 = Nothing Set db = Nothing Set rst = Nothing Exit Sub Error_Handler: Call ErrorMessage(Err.Number, Err.Description, "Form_frmAdminForms: Form_Load") Resume Exit_Procedure Resume End Sub
Comment