Solved

Collection Question

Posted on 2000-04-28
3
197 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
3 Comments
 
LVL 1

Accepted Solution

by:
jgravelle earned 50 total points
Comment Utility
You might want to try changing the line

lstMyData.AddItem Mydata to
lstMyData.AddItem Y


0
 
LVL 4

Expert Comment

by:TigerZhao
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

10 Experts available now in Live!

Get 1:1 Help Now