MS ACCESS - 如何在更改事件中获取未绑定组合框的当前列值

MS ACCESS - How to get the current columns values of an unbound combobox on Change event

我有一个包含 3 列的未绑定组合框:项目、序列号和成本。

我在上面添加了一个 Change 事件,当我 select 下拉组合中的一行时,我需要将 3 个当前值全部放在一个文本框中,并分别放在其他文本框中。

例如:我点击组合框并从列表中随机选择一行

Private Sub combo_Change()
textbox1.value = 'current column1+col2+col3 values
text2.value= 'current col1 value
text3.value= ' current col2 value
text4.value= 'current col3 value
end sub

我该怎么做?

按索引引用组合框或列表框的列。索引从 0 开始,所以第 2 列是索引 1。

Me.textbox1 = Me.combobox1 & Me.combobox1.Column(1) & Me.combobox1.Column(2)

如果要添加,则必须转换为数字,因为所有列都是字符串。

Me.textbox1 = Val(Me.combobox1) + Val(Me.combobox1.Column(1)) + Val(Me.combobox1.Column(2))

试试下面的子。

Private Sub cmbItems_Change()
Dim str1, str2, str3

    str1 = Me.cmbItems.Column(0)
    str2 = Me.cmbItems.Column(1)
    str3 = Me.cmbItems.Column(2)
    
    Me.Text0 = str1 & ", " & str2 & ", " & str3
    Me.Text1 = str1
    Me.Text2 = str2
    Me.Text3 = str3

End Sub