根据组合框中的选择显示值 vba

Show value based on selection in combo box vba

我需要在访问表单中根据组合框中的选择显示面额

这里棘手的是我需要在组合框中选择后立即显示(不保存)。这个在我保存我的选择后就开始工作了。

If cmb_Main_Impact.Value = "Productivity" Then
Me.txt_Units = "minutes"
End If

If cmb_Main_Impact = "Quality" Then
Me.txt_Units = "number of errors"
End If

该代码应该可以正常工作。您想在更改事件时将其放入组合框中。

还添加了一个 elseif,因此没有多个 if 和 end if。将该代码放入具有组合框的用户窗体中。

因此您的代码将如下所示。

Private Sub cmb_Main_Impact_Change()

    If cmb_Main_Impact.Value = "Productivity" Then
        Me.txt_Units = "minutes"

    elseIf cmb_Main_Impact = "Quality" Then
        Me.txt_Units = "number of errors"
    End If

End Sub