LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Iterate over Collection Objects in Container.

Is it possible to Set an object to a string reference?

No. A String is not an object in VB. You can *add* a String to a Collection
or assign a String to a String or Variant property of an object..

collectionobject.Add "some string"

label.Caption = "some string"

--
Bob Kilmer


"Paul M" wrote in message
...
Hi,

I have a question that I hope can be answered quickly.
I'm sure there must be a way of doing it.

I have three Public Collections dimmed in a Sub.
I have a For Each statement iterating over the controls
on a form returning List Boxes with Selected Items. I can
get the controls to iterate, but can't get the
Collections to change as well.

Basically, the Control Name is the Collection Name Mid(4)

So:

Control Name = lbxOwner
Collection Name = Owner or Preferably colOwner if
possible to add col & the mid statement.

The problems is I dim the Control.Name as a variable
called ActColName as String, but I can't set the object
(ActCollection) as Collection because of the string
dimension.

Is it possible to Set an object to a string reference?

In the immediate window if you type:

Set actCollection = colOwner
It works
But you get an Object Error if you try
Set actCollection = ActColName (Where ActColName =
colOwner as String)


Here is the sample code (Including only the Dimensions
referenced here)
Public colOwner As New Collection
Public colCoOrdinator As New Collection
Public colAdministration As New Collection
Dim Item As Collection
Dim ListIndex As Variant
Dim i As Control
Dim ActControl As Object
Dim ActCollection As Collection
Dim ActColName As Variant
Dim itemSelected As Boolean
For Each i In fmDivReport.Controls
If i.Name Like "lbx*" Then
ActColName = "col" & Mid(i.name, 4)
Set ActControl = i
Set ActCollection = ActColName ' This is
where it errors
For ListIndex = 0 To ActControl.listCount - 1
If ActControl.Selected(ListIndex) = True
Then
ActCollection.Add ListIndex
Debug.Print ActControl.Name & " " &
ActControl.List(ListIndex)
itemSelected = True
End If
Next ListIndex
End If
ListIndex = 0
Next i

-----
Any help would be great.

Many Thanks in Advance

Paul M.



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
series objects; finding specific ones in the collection cate Charts and Charting in Excel 2 April 4th 10 03:25 PM
SOLVER does not iterate / work BHatMJ Excel Discussion (Misc queries) 4 August 12th 09 10:42 PM
Using Container in Auto open macro [email protected] Excel Discussion (Misc queries) 0 November 9th 06 11:22 AM
Iterate Circular Reference Brandt Excel Discussion (Misc queries) 1 August 3rd 05 11:43 PM
Excel funtion to find how many boxes in larger container logistics learner Excel Worksheet Functions 3 December 21st 04 01:18 AM


All times are GMT +1. The time now is 02:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"