CONCATENATE collection string

S

Souris

I have a collection and add the items in the loop.

I would like to check if the item exists, if yes, I will concatenate with
original and new information, f not I just need add new one.

My code is like following, but it works only null string,

If Len(MyCollection.Item(i).Value) = 0 Then
MyCollection.Add """" + (Myrs.Fields![MyCode].Value) + """"
Else
MyCollection.Item(i) = MyCollection.Item(i).Value + """" +
(Myrs.Fields!MyCode].Value) + """"
End If


It only works when the len result is zero, but it fails when the len result
great than zero.

Your information is great appreciated,
 
M

Marshall Barton

Souris said:
I have a collection and add the items in the loop.

I would like to check if the item exists, if yes, I will concatenate with
original and new information, f not I just need add new one.

My code is like following, but it works only null string,

If Len(MyCollection.Item(i).Value) = 0 Then
MyCollection.Add """" + (Myrs.Fields![MyCode].Value) + """"
Else
MyCollection.Item(i) = MyCollection.Item(i).Value + """" +
(Myrs.Fields!MyCode].Value) + """"
End If

It only works when the len result is zero, but it fails when the len result
great than zero.


Assuming that MyCollection is a VBA Collection object.

There are two ways to determine if an item exists in the
collection. One is to try to reference the item and trap
the error if it is not there. The other is to iterate
through the existing entries in the collection and compare
each entry to the item.

There are two operations that can be performed on a
collection item. You can Add new items to the collection
and you can Remove an item. You can not modify an existing
item in the collection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top