Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Listbox Problem using List Property - Missing Reference?

Posted on 2011-09-16
3
Medium Priority
?
447 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 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1200 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 35

Accepted Solution

by:
Norie earned 800 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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

885 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