I have problem with adding values to multiple columns in listbox in access. I have tried solution like this: Adding items in a Listbox with multiple columns and this: vba listbox multicolumn add [duplicate], but it doesn't work. Listbox in my case hasn't a property "List". I have compile error:
Private Sub cmdAddPosition_Click()
Dim i As Integer
Me.lstAddPositions.ColumnCount = 7
If Me.txtAddPos.Value = i And i > 0 And i < 50 Then
Me.lstAddPositions.AddItem (Me.txtAddPos.Value)
'Me.lstAddPositions.AddItem(Me.txtAddPos.Value,(i))
Me.lstAddPositions.List(0, i) = Me.txtAddPos.Value
'Me.lstAddPositions.Column(0, i) = Me.txtAddPos.Value 'adding number of position
'Me.lstAddPositions.Column(2, i) = Me.lstAddHidden.Column(0, 0) 'adding titel
End If
Me.lstAddPositions.Requery
End Sub
What can I do in this situation?
select propety
Row Source Type => Value List
Code :
ListbName.ColumnCount=2
ListbName.AddItem "value column1;value column2"
Here is an example of adding items to a multi-column unbound list box on an access form if the row source is a value list. You have to add it by creating a string that you place in a value list.
Private Sub cmdAddPosition_Click()
Dim i As Integer
Me.lstAddPositions.ColumnCount = 7
If Me.txtAddPos.Value = i And i > 0 And i < 50 Then
Me.lstAddPositions.AddItem "Col1" & "," & "col2" & "," & "Col3" & "," & _
"Col4" & "," & "Col5" & "," & "col6" & "," & "col7" &";"
End If
Me.lstAddPositions.Requery
End Sub
Row source type: value list Column count: 2
Suppose name of list box is : listName Let us assume that u want to add two different elements in two different columns and two different strings are stored in
String1 and String2 then follow the code
Code:
Dim strName as string
strName=String1&";"&String2
Me.listName.addItem strName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With