473,383 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Collection object help - driving me crazy

ck
Sorry for the cross post.

What is wrong with this code?--ado recordset to populate a collection--see
reason below
Dim myCol2 As New Collection
On Error Resume Next
Do While Not rs.EOF
myCol2.Add rs!Email, rs!Email
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
oConn.Close
Set oConn = Nothing

MsgBox myCol2.Count

For Each Item In myCol2
Set rcp = ml.Recipients.Add(myCol2(Item))
rcp.Type = olBCC
Next

-------The msgbox shows the correct count but I can not get the string data
from each item. What am I missing?? I have tried a counting for x = 1 to
myCol2.count and fox x=mycol2.count to 1 step -1... I can not figure out
what I am overlooking. I believe the collection object is being populated
correctly. I think it's something around my on error resume next line of
code. I am trying to get email addresses from my db. That works fine. I
want to loop through those records and add the email address as the item
and the key values to the collection object. This will prevent more than one
of the same email address. I then want to loop through the collection and
add each item to the recipients collection of an outlook.mailitem. I can
make everything work if I skip the collection, but this lets the same email
address be added any number of times. Thanks everybody.
~ck
Nov 13 '05 #1
3 1618
ck wrote:
Sorry for the cross post.

What is wrong with this code?--ado recordset to populate a collection--see
reason below
Dim myCol2 As New Collection
On Error Resume Next
Do While Not rs.EOF
myCol2.Add rs!Email, rs!Email
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
oConn.Close
Set oConn = Nothing

MsgBox myCol2.Count

For Each Item In myCol2
Set rcp = ml.Recipients.Add(myCol2(Item))
rcp.Type = olBCC
Next

-------The msgbox shows the correct count but I can not get the string data
from each item. What am I missing?? I have tried a counting for x = 1 to
myCol2.count and fox x=mycol2.count to 1 step -1... I can not figure out
what I am overlooking. I believe the collection object is being populated
correctly. I think it's something around my on error resume next line of
code. I am trying to get email addresses from my db. That works fine. I
want to loop through those records and add the email address as the item
and the key values to the collection object. This will prevent more than one
of the same email address. I then want to loop through the collection and
add each item to the recipients collection of an outlook.mailitem. I can
make everything work if I skip the collection, but this lets the same email
address be added any number of times. Thanks everybody.
~ck


Here's a quick example
Sub ColTest()
Dim col As New Collection
Dim var As Variant
col.Add "test1"
col.Add "test2"

For Each var In col
MsgBox var
Next
Set col = Nothing
End Sub

Nov 13 '05 #2
rkc

"ck" <c_**********@hotmail.com> wrote in message
news:1w***************@newssvr27.news.prodigy.com. ..
Sorry for the cross post.

What is wrong with this code?--ado recordset to populate a collection--see
reason below
Dim myCol2 As New Collection
On Error Resume Next
Do While Not rs.EOF
myCol2.Add rs!Email, rs!Email
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
oConn.Close
Set oConn = Nothing

MsgBox myCol2.Count

For Each Item In myCol2
Set rcp = ml.Recipients.Add(myCol2(Item))
rcp.Type = olBCC
Next


First of all, rs!Email is a ado.field object. What you are doing is adding
the
ado.field object that rs!Email represents to to the collection. What you
think
you are doing is adding the rs!Email.Value to the collection.

So the solution is do what you think you are doing. Use rs!Email.Value.

Also, your for each loop should look like:

For Each Item In myCol2
Set rcp = ml.Recipients.Add(Item)
rcp.Type = olBCC
Next




Nov 13 '05 #3
Hi,
Try This.

Dim myCol2 As Collection
Dim Item as variant

On Error Resume Next

set myCol2=new collection

Do While Not rs.EOF
myCol2.Add rs!Email,"'" & rs!Email & "'" ' Otherwise if not required
just remove the collection key
rs.MoveNext
Loop
rs.Close

Set rs = Nothing
oConn.Close
Set oConn = Nothing

MsgBox myCol2.Count
For Each Item In myCol2
Set rcp = ml.Recipients.Add(myCol2(Item))
rcp.Type = olBCC
Next

set myCol2=nothing

Mustafa,
"Salad" <oi*@vinegar.com> wrote in message
news:RQ******************@newsread2.news.pas.earth link.net...
ck wrote:
Sorry for the cross post.

What is wrong with this code?--ado recordset to populate a collection--see reason below
Dim myCol2 As New Collection
On Error Resume Next
Do While Not rs.EOF
myCol2.Add rs!Email, rs!Email
rs.MoveNext
Loop

rs.Close
Set rs = Nothing
oConn.Close
Set oConn = Nothing

MsgBox myCol2.Count

For Each Item In myCol2
Set rcp = ml.Recipients.Add(myCol2(Item))
rcp.Type = olBCC
Next

-------The msgbox shows the correct count but I can not get the string data from each item. What am I missing?? I have tried a counting for x = 1 to myCol2.count and fox x=mycol2.count to 1 step -1... I can not figure out
what I am overlooking. I believe the collection object is being populated correctly. I think it's something around my on error resume next line of
code. I am trying to get email addresses from my db. That works fine. I want to loop through those records and add the email address as the item and the key values to the collection object. This will prevent more than one of the same email address. I then want to loop through the collection and add each item to the recipients collection of an outlook.mailitem. I can make everything work if I skip the collection, but this lets the same email address be added any number of times. Thanks everybody.
~ck


Here's a quick example
Sub ColTest()
Dim col As New Collection
Dim var As Variant
col.Add "test1"
col.Add "test2"

For Each var In col
MsgBox var
Next
Set col = Nothing
End Sub

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
34
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple,...
5
by: Sean Hearne | last post by:
I have numerous collections (currently ArrayLists) which contain objects of the same type. I need some way of aggregating these lists into one collection with duplicate objects only appearing once...
4
by: Adam Dockter | last post by:
Okay something has been driving me crazy. I see in the MSDN documentation that ToolBar.ToolBarButtonCollection implements the IList interface. The I look at members in the ToolBars.Buttons...
5
by: Kurt Van Campenhout | last post by:
Hi, I am trying to get/set Terminal server information in the active directory on a windows 2000 domain. Since the ADSI calls for TS don't work until W2K3, I need to do it myself. I'm fairly...
1
by: Miguel Dias Moura | last post by:
Hello, I have been trying, for days, to retrieve a control's ClientId in a javascript function. I am using a master page and this is why I need to retrieve the Control's ClientId. The control...
0
by: bryanp10 | last post by:
I'm working on a project that uses some older VB6 COM objects. One of the classes returns a Collection object, which I am having trouble reading in C#. Can someone point me in the right direction...
4
by: egewitz | last post by:
I keep getting this error and it's driving me crazy: 3265 - Item Not Found In This Collection I'm using MS Access 2003. Through VBA I'm attempting to fill in an excel spreadsheet with a query...
3
by: rashpal.sidhu | last post by:
Please help, this problem is driving me crazy !! I am using metaphone to create phonetic keys. When i run the module stand-a-lone it works fine. I'm trying to create a runner for informix...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.