运行 Access 中的 VBA 代码

Running a VBA code within Access

我目前在 Access 2013 中工作。如果选择按钮(yes/no 字段),我想在子表单中锁定两个字段,这两个字段包括恢复以前的位置和个人参考, yes/no 字段是 Resume Source Internal。

我的代码:

Private Sub Resume_Source_Internal_Click()
   If [Resume Source Internal].Value = True Then
      [Personal Reference].Enabled = True
      [Resume Previous Location].Enabled = False
   Else
      [Personal Reference].Enabled = True
      [Resume Previous Location].Enabled = False
   End If
End Sub

我遇到的问题是当我选择按钮 (yes/no) 时没有任何反应。我以前有 运行 这段代码的另一种形式,它运行良好。有什么我可能错过的吗? Personal Reference 和 Resume Previous Location 都是查找字段。

试试这个:

Private Sub Resume_Source_Internal_Click()
   If [Resume Source Internal].Value = True Then
      [Personal Reference].Enabled = True
      [Resume Previous Location].Enabled = False
   Else
      [Personal Reference].Enabled = False
      [Resume Previous Location].Enabled = True
   End If
End Sub

请注意,在 Else 中,我调换了 FalseTrue 的值。如您所写,您在 If...Else

的两侧设置了完全相同的值

此代码是否适合您 - 在 属性 Sheet.

中将字段设置为一个启用和一个禁用

当您单击按钮时,启用的 属性 将从 True 切换为 False,反之亦然。

Private Sub Resume_Source_Internal_Click()

    Me.Personal_Reference.Enabled = Not Me.Personal_Reference.Enabled
    Me.Resume_Previous_Location.Enabled = Not Me.Resume_Previous_Location.Enabled

End Sub