Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset-Like Data Collection

Status
Not open for further replies.

svagelis

Programmer
May 2, 2001
121
GR
I have created a simple class named customer that handles data for a customer. Retrieves,updates customer's data etc.
Well when i m dealing with more than one customer i think i should deal with a collection of customers.

p.e. i should be able to do this

dim objCustomers as new colCustomers
dim objCustomer as clsCustomer

objCustomers.Open lngID

for each objCustomer In objCustomers
debug.Print objCustomer.Name
next

Any help would be appreciated
 
I do not know what you want exactly.

If you want to use a standard collection (of variants), you'll have to create the objCustomer objects first and store them in the collection objCustomers.

If you want to write your own collection class, the database functionality should be encapsulated by it. That means that it should behave like a collection, but handle database stuff internally. Normally, you would define an
Code:
item()
method that returns an objCustomer object somehow. It is wise to give the collection class a constuctor-like (initialization) method as well, where you can pass in the table or database that hold the information.

There are numeruous ways to go from here:
Your
Code:
item()
method can create an object directly from the database data, or keep some private storage (an array or a standard collection) for objects that were previously retrieved from the database (you have built a "lazy collection" then).
If you need to make changes to the objects, you could pass a reference to the collection class to each member object, so they can ask the collection class to update the database to their new state. If you do that, be careful to implement some cleanup method on the collection class and the member objects themselves, otherwise the member objects and the collection class keep references to each other and cannot be cleaned up automatically.

Hope this helps or amuses
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top