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

时间:2023-01-27 20:19:42

I need to show denominations based on selection in combo box in my access form.

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

The tricky thing here is that I need to show immediately after selecting in the combo box (without saving it). This one is working just after I save my selection.

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

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

1 个解决方案

#1


That code should work fine. You want to put it in the combobox on change event.

该代码应该可以正常工作。你想把它放在变化事件的组合框中。

Also added an elseif so there isnt multiple if and end ifs. Put that code in in the userform that has the combo box.

还添加了一个elseif,所以没有多个if和end ifs。将该代码放在具有组合框的userform中。

So your code will look like.

所以你的代码看起来像。

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

#1


That code should work fine. You want to put it in the combobox on change event.

该代码应该可以正常工作。你想把它放在变化事件的组合框中。

Also added an elseif so there isnt multiple if and end ifs. Put that code in in the userform that has the combo box.

还添加了一个elseif,所以没有多个if和end ifs。将该代码放在具有组合框的userform中。

So your code will look like.

所以你的代码看起来像。

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