Results 1 to 11 of 11

Thread: Creating MultiColumns ListBox from VBA array

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Creating MultiColumns ListBox from VBA array

    Hi,

    I'm trying to create a listbox regarding to a VBA "virtual" array I have.

    for example:

    Dim MyArray(3, 3)

    For i = 1 To 3
    For k = 1 To 3
    MyArray(i, k) = i & k
    Next
    Next

    Now, I want to enter the data to a multicolumn listbox (3 X 3) but don't know how.

    Help?

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating MultiColumns ListBox from VBA array

    Simple way - works until you get lots of data...

    set the list box to values, the column count to 3

    then create a string using your loop to add each item to display per row together.

    example string
    1;2;3;1;2;3;1;2;3

    Then set the rowsource to the string you make.

    Possibly requery the list box too.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Creating MultiColumns ListBox from VBA array

    Not Working.. what did I do wrong?

    VB Code:
    1. MyStr = ""
    2.  
    3.     For i = 1 To XmlLastColumn
    4.         MyStr = MyStr & XMLcolumns(i) & ";"
    5.     Next
    6.    
    7.     MyStr = Left(MyStr, Len(MyStr) - 1)
    8.    
    9.     frmXmlColumns.lstXmlCol.RowSource = MyStr

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating MultiColumns ListBox from VBA array

    Code:
    Dim MyArray(3, 3)
    
    For i = 1 To 3
        For k = 1 To 3
            MyArray(i, k) = i & k
            strToDisp = strToDisp & iif(len(strToDisp)>0,";","") & i & k
        Next
    Next
    
    frmXmlColumns.lstXmlCol.RowSource = MyStr
    Have you set the list box to values and set the column count to 3 (probably need to set the column widths to "1;1;1" as well) ?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Creating MultiColumns ListBox from VBA array

    OK... got the prob.. how do I set the listBox to values?

  6. #6
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating MultiColumns ListBox from VBA array

    in MS Access

    Design view
    Select the list box
    Right click > Properties (if the window isn't open)
    Change to Data tab
    The rowsource and type are there. Change the type to values.
    Change tab back to format (the first tab)
    Change column count and column widths here
    Save form
    Close and see if the code runs

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Creating MultiColumns ListBox from VBA array

    I'm sorry, I should have say that befrore - I'm using Excel, not Access. No "Type" field overthere...

  8. #8
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating MultiColumns ListBox from VBA array

    I had a feeling you were going to say that.

    Ok.. I tried via a userform > list box On the properties window, change to categorised. scroll down to data - should be on there.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Creating MultiColumns ListBox from VBA array

    Sorry. No "Type" fuels ynder Data Category...

    Excel do have:
    1. BoundColumn (1)
    2. ColumnCount (3)
    3. ColumnHeads (False)
    4. ColumnWisths
    5. ControlSource
    6. ListStyle (0 - fmListStylePlain)
    7. RowSource
    8. Text
    9. TextColumn (-1)
    10. TopIndex (-1)

  10. #10
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating MultiColumns ListBox from VBA array

    Try Rowsource for the string data. Forget the type. I was thinking in Access sorry

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  11. #11

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    6

    Re: Creating MultiColumns ListBox from VBA array

    It didn't work... It works only for "real" source as rows and columns in the Excel sheet..

    I will manage without it...

    Thanks!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width