我的表单中有以下代码:
txtFrontname.Locked = False
txtFrontname.BorderStyle = 4
txtFrontname.BorderColor = RGB(255, 165, 0)
txtLastname.Locked = False
txtLastname.BorderStyle = 4
txtLastname.BorderColor = RGB(255, 165, 0)
txtAdress.Locked = False
txtAdress.BorderStyle = 4
txtAdress.BorderColor = RGB(255, 165, 0)
有没有办法合并这段代码?所以我的代码变短了? 像所有。锁定在1行,所有.Borderstyle在1行,所有.BorderColor在1行?
答案 0 :(得分:0)
您可以使用选择案例:
Dim Control As Access.Control
For Each Control In Me.Controls
If Control.ControlType = acTextBox Then
Select Case Control.Name
Case _
"txtFrontname", _
"txtLastname", _
"txtAdress"
With Control
.Locked = False
.BorderStyle = 4
.BorderColor = RGB(255, 165, 0)
End With
End Select
End If
Next
Set Control = Nothing