Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Collection Question

Posted on 2000-04-28
3
Medium Priority
?
204 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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Suggested Courses

730 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