Solved

Listbox Problem using List Property - Missing Reference?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending email from List Data 2 51
Error in query expression 3 37
MS Access 03, TransferText, decimal places 8 46
VBA code won't run Delete Query 5 25
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

895 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

17 Experts available now in Live!

Get 1:1 Help Now