我有一个Access 2010形式称为[P101]至[P110],它是指在源表中的字段[P101]至[P110] 20个上的文本框。 该可包含值或没有,但如果没有,我不希望看到他们。 我也有在已统计有多少场都在使用该表中的字段[UsedFields。 在Form_Current我可以设置下面的代码,但有什么办法,我可以设置一个For Next循环使用一个变量的字段名称? 当前的代码(这工作,但很笨拙)是:
If UsedFields > 0 then
P101.Visible = True
Else
P101.Visible = False
End If
If UsedFields > 1 then
P102.Visible = True
Else
P102.Visible = False
End If
.
.
.
.
If UsedFields > 9 then
P110.Visible = True
Else
P110.Visible = False
End If
作为场的数量设置为10增加到100,我想用一个变量来保存文本框的名字,是这样的:
Private Sub Form_Current()
Dim Ctrl As Control
Dim CtrlName As String
Dim Counter As Long
For Counter = 1 To 10
CtrlName = "P" & Counter
Set Ctrl = CtrlName
If Counter > Me.UsedFields Then
Ctrl.Visible = False
Else
Ctrl.Visible = True
End If
End Sub
就是这样一个基准可能吗?