Solved

Listbox Problem using List Property - Missing Reference?

Posted on 2011-09-16
3
430 Views
Last Modified: 2012-05-12
Hi Experts,

I'm trying to use an array to populate a listbox, however the 'list' property is causing 'Run-time error 438 - Object doesn't support this property or method'.  The code below is that provided in Microsofts Help and the following line is the affending one.
ListBox1.List() = MyArray

I'm using MS Access 2007.

I can only think that I have a missing reference or something.  Any suggestions?

Many Thanks,

Oliver
Dim MyArray(6, 3)           

'Array containing column values for ListBox.



Private Sub UserForm_Initialize()

    Dim i As Single



    ListBox1.ColumnCount = 3        

'This list box contains 3 data columns



    'Load integer values MyArray

    For i = 0 To 5

        MyArray(i, 0) = i

        MyArray(i, 1) = Rnd

        MyArray(i, 2) = Rnd

    Next i



    'Load ListBox1

    ListBox1.List() = MyArray



End Sub

Open in new window

0
Comment
Question by:Oliver Wastell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 300 total points
ID: 36550796
Are you doing this in Access? If so, then an Access Listbox doesn't have the List propery. If you're going to populate a Listbox like this, set the RowSourceType to "Value List", the ColumnCount to 3, and your ColumnWidths to 1;1;1. Then add your items using the .AddItem method:

 For i = 0 To 5

       Me.Listbox.AddItem i & ";" & Rnd & "';" & Rnd

    Next i

0
 
LVL 34

Accepted Solution

by:
Norie earned 200 total points
ID: 36550827
Oliver

You can't use List in Access.

There's also no userforms in Acess and therefore no userform Initialize event.

If you do have an unbound form in Access with a 3-column listbox you can populate it like this.

Option Compare Database
Option Explicit

Private Sub Form_Load()
Dim I As Long

    Listbox1.RowSourceType = "Value List"
    Listbox1.ColumnCount = 3

    For I = 0 To 5
        Listbox1.AddItem I & ";" & Rnd & ";" & Rnd
    Next I

End Sub

Open in new window

0
 
LVL 3

Author Closing Comment

by:Oliver Wastell
ID: 36552096
Hi LSM Consulting / imnorie,

Thank you both for you quick replies, only a few minutes between you.    Both your solutions are clear.  I've awarded 300 to LSM Consulting for being slightly quicker off the mark, and 200 to imnorie.  I hope you both deem this fair.

Best Regards and Thanks!

Oliver
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Query - calculate End of the Month in Query 2 54
access vba 5 58
Excel graph in access report 1 34
Select category, subcategory in MS Access table field 7 45
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question