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
Solved

Collection Question

Posted on 2000-04-28
3
201 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

829 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