Solved

Listbox Problem using List Property - Missing Reference?

Posted on 2011-09-16
3
403 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
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 33

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now