2014-01-19 69 views
2

我怎样才能缩短此代码?我已经把他们的标签名称作为Group_Sal1?在访问表单上将控件分组在一起启用

Public Function Salary_Text_Editable() 
    Me.BasicSal.Enabled = True 
    Me.HouseAllow.Enabled = True 
    Me.TransAllow.Enabled = True 
    Me.PetrolAllow.Enabled = True 
    Me.AirfareAllow.Enabled = True 
    Me.MobileAllow.Enabled = True 
    Me.COLA.Enabled = True 
    Me.OtherAllow.Enabled = True 
    Me.SiteAllow.Enabled = True 
    Me.RemoteAllow.Enabled = True 
    Me.FoodAllow.Enabled = True 
    Me.EWOT.Enabled = True 
    Me.SaudiAllow.Enabled = True 
    Me.QatarAllow.Enabled = True 
    Me.BaynunahAllow.Enabled = True 
    End Function 

回答

1

遍历窗体的Controls收集和检查每个Tag财产。如果其标记匹配“Group_Sal1”,则启用该控件。

Public Function Salary_Text_Editable() 
    Dim ctl As Control 
    For Each ctl In Me.Controls 
     If ctl.Tag = "Group_Sal1" Then 
      ctl.Enabled = True 
     End If 
    Next 
End Function 
+0

非常感谢您的帮助。但不幸的是我仍然有调试。我不知道为什么? –

相关问题