Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding values multiple columns to listbox in form access vba

Tags:

vba

ms-access

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:

enter image description here

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?

like image 243
Beacze Avatar asked Sep 18 '13 11:09

Beacze


3 Answers

select propety

Row Source Type => Value List

Code :

ListbName.ColumnCount=2

ListbName.AddItem "value column1;value column2"

like image 27
KONG Avatar answered Oct 09 '22 04:10

KONG


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
like image 179
Zaider Avatar answered Oct 09 '22 06:10

Zaider


Firstly set the following properties for list box

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
like image 36
Sudeep kumar naru Avatar answered Oct 09 '22 06:10

Sudeep kumar naru