Option Compare Database
Private Sub Form_AfterUpdate()
Me.Refresh
End Sub
Private Sub MedicalCondition_AfterUpdate()
If Me.MedicalCondition = True Then
' If Yes is selected, enable HealthStatus and HealthDescription
Me.HealthStatus.Enabled = True
Me.HealthStatusDESCR.Enabled = True
Else
' If No is selected, disable HealthStatus and HealthDescription
Me.HealthStatus.Enabled = False
Me.HealthStatusDESCR.Enabled = False
End If
' Requery the form to refresh the controls
Me.Requery
End Sub
该字段的名称是 MedicalCondition,有是/否选项。
用户选择后,它将禁用或启用 HealthStaus 和 HealthStatusDESCR 字段。
如果用户选择“是”,则启用 2 个字段;
如果用户选择“否”,则禁用这 2 个字段。
我查看了命名字段,没有发现任何错误。
您不需要
Requery
或 Refresh
来启用/禁用控件。删除所有这些。
如果您的组合框具有“是”和“否”作为值,则无法测试
True
。
尝试
Private Sub MedicalCondition_AfterUpdate()
' Ctrl+G opens Immediate Window where this goes:
Debug.Print "MedicalCondition: " & Me.MedicalCondition.Value
If Me.MedicalCondition.Value = "Yes" Then
如果“是”不起作用,请检查 Debug.Print 输出。
您可以使用变量简化代码:
Private Sub MedicalCondition_AfterUpdate()
Dim bMedicalCondition As Boolean
bMedicalCondition = (Me.MedicalCondition.Value = "Yes")
' No need for If Then Else:
Me.HealthStatus.Enabled = bMedicalCondition
Me.HealthStatusDESCR.Enabled = bMedicalCondition
End Sub