Solved

Collection Question

Posted on 2000-04-28
3
199 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
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 142

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

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
vb6 programatically bring window to front 8 65
Cannot enter table caption text in Word protected document 6 114
Determine Range to Select 5 43
Adding to a VBA? 6 63
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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

863 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

27 Experts available now in Live!

Get 1:1 Help Now