【问题标题】:Enabling/disabling input into certain record's field based on the value of another field, but at the same record根据另一个字段的值启用/禁用对某个记录字段的输入,但在同一记录
【发布时间】:2020-07-06 06:46:28
【问题描述】:

我使用 Access 2016 并尝试锁定/解锁每条记录中的字段(Epileptic_activity、Quantifiable_activity 和 Seizure_aspect),当“选择”分别=否/是时(我在选择中选择是/否)。所有这些都发生在大导航表单的子表单中。

我用了这个方法 Enabling/disabling input into certain fields based on the value of another field 它可以工作,但它会锁定/解锁表单中显示的所有数据。 一旦我将任何选择选中为是,所有记录都已解锁 Epileptic_activity、Quantifiable_activity 和 Seizure_aspect。

这是我使用的代码:

Private Sub Selection_AfterUpdate()

Me.Epileptic_activity.Enabled = True

Me.Quantifiable_activity.Enabled = True

Me.Seizure_aspect.Enabled = True

If (Me.Selection = False) Then

    Me.Epileptic_activity.Enabled = False

    Me.Quantifiable_activity.Enabled = False

    Me.Seizure_aspect.Enabled = False

    End If

End Sub

所以,我希望能够在选择记录之后锁定/解锁字段,因为在一条记录中我们可以有选择并且以下字段是必需的,但下一条记录没有选择=“是”并且那么我希望锁定以下 3 个字段。

我怎样才能让它工作?

感谢任何帮助

【问题讨论】:

    标签: vba ms-access ms-access-2016


    【解决方案1】:

    您无法更改这一点,这就是 Access 的工作方式。

    但是,您可以通过检查Selection 值在每次控件获得焦点时单独启用/禁用每个控件。

    Private Sub Epileptic_activity_Enter()
    
        If Selection.Value = False Then Epileptic_activity.Enabled = False Else Epileptic_activity.Enabled = True
    
        'or simply
    
        Epileptic_activity.Enabled = Selection.Value
    
    End Sub
    

    您需要对所有三个控件执行此操作。

    【讨论】:

    • 谢谢。有用。可惜,不能逐行禁用,不过OK,可以这样
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多