Solved

Collection Question

Posted on 2000-04-28
3
203 Views
Last Modified: 2010-05-02
I need to provide code to fill a listbox with the contents of a collection named "MyData".  What is the matter with what I wrote?

Option Explicit
Dim Mydata As New Collection

Private Sub cmdShow_Click()
Dim Y As String

lstMyData.Clear
For Each Y In Mydata
    lstMyData.AddItem Mydata
Next Y

End Sub

I've been fighting with this for days.  Any help would be greatly appreciated.
0
Comment
Question by:BooBooxGalore
[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 1

Accepted Solution

by:
jgravelle earned 50 total points
ID: 2760863
You might want to try changing the line

lstMyData.AddItem Mydata to
lstMyData.AddItem Y


0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 2761822
For Each control variable must be variant or Object
Like This:
Private Sub cmdShow_Click()
Dim Y As Long

lstMyData.Clear
For Y = 1 To Mydata.Count
    lstMyData.AddItem Mydata(Y)
Next Y

End Sub
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2762006
This is a killing answer :-)

Private Sub cmdShow_Click()
Dim Y As Variant

lstMyData.Clear
For each y in MyData
    lstMyData.AddItem Y
Next
End Sub


0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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