0
votes

I have an unbound combobox with 3 columns: item, sn and cost.

I added a Change event on it and when i select one row from the drop down combo, i need the 3 current values all together in a textbox and separately in other texboxes.

Ex: i click on the combobox and choose a random row from the list

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

how can i do that?

2
Why use VBA? Are you trying to save to fields in table? Why save this calculated data to table? That would duplicate data to multiple tables. It can be calculated when needed. These expressions can just be in textbox ControlSource:=combobox1 & combobox1.Column(1) & combobox1.Column(2)June7

2 Answers

1
votes

Try below sub.

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

enter image description here

0
votes

Reference columns of combobox or listbox by their index. Index begins with 0 so column 2 is index 1.

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

If you want to add, will have to convert to number because all columns are strings.

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