Solved

Collections

Posted on 2000-03-06
7
354 Views
Last Modified: 2010-05-02
Why can't a programmer add more than one occurance of an object to a collection in the same procedure, ie..  while processing result sets, Vb6 would not add the correct result set field data to the collection in the same procedure.  I had to create an add sub procedure and pass it the record in order to have it added to the collection properly.  Listed below is an example:

This did not work properly:

While RDORS not EOF

 move RSFields to object fields
 Add to collection
 RS.Movenext

Wend

This did work:

While RDORS not EOF

 Call subprocedure passing RDORS object
 (subprocedure add to collection)
 RS.Movenext

Wend


TIA,
jjjjjjj














0
Comment
Question by:jjjjjjj
[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
7 Comments
 
LVL 4

Expert Comment

by:wesleystewart
ID: 2588965
Can you paste the exact code here that didn't work?

Wes
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2590192
What it looks like to me, is that in the first case (the one that didn't work).. you did not create a collection object before hand.. and that in the second case (the procedure).. you probably did.

Try this code out (I am using a Listview collection as an example)

Dim itmWork as Listitem

While RDORS not EOF

  ' Create collection object
  Set itmWork = lvwListview.ListItems.Add()

  ' Move fields
  With itmWork
    .Key = Rs.Key    
    .SmallIcon = NameOfPicture
    .Text = Rs.Text
    .subitems(1) = Rs.Field1
    .subitems(2) = Rs.Field2
    .subitems(3) = Rs.Field3
  End With

  ' Get Next Record
  RS.Movenext

Wend


0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 2594949
follow code did not work

Dim o as New Collection
'...
o.Add rs!Field1
'...
rs.Close
'...
debug.print o(I)

Because you add the Field OBJECT to the collection, after recordset close, the field object cann't access, the right way is:

o.Add rs!Field1.Value
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:jjjjjjj
ID: 2597702
I am deleting because I have solved the issue separately, without using any of the comments.

The reason why it does not work is due to scope.  I have resolved by re-establishing the proper scope.

jjjjjjj
0
 
LVL 1

Author Comment

by:jjjjjjj
ID: 2597703
This question has a deletion request Pending
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2597889
This question no longer is pending deletion
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 50 total points
ID: 2597890
from my earlier comment.. << you did not create a collection object before hand.. and that in the second case (the procedure).. you probably did >>

Scope is everything.. <smile>

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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
Course of the Month6 days, 21 hours left to enroll

622 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