[AccessD] Advanced Unbound Form With ClassesandCollectionsP art 3

William Hindman wdhindman at dejpolsystems.com
Wed Jun 28 12:04:27 CDT 2006


...lol ...fat chance :)

William

----- Original Message ----- 
From: <DWUTKA at marlow.com>
To: <accessd at databaseadvisors.com>
Sent: Wednesday, June 28, 2006 11:58 AM
Subject: Re: [AccessD] Advanced Unbound Form With ClassesandCollectionsP art 
3


> I'll think about it, need to find the time to do it.  Maybe if you just 
> gave
> in on the 'ex Bird flu' thread, I'd have more time on my hands! ;)
>
> Drew
>
> -----Original Message-----
> From: William Hindman [mailto:wdhindman at dejpolsystems.com]
> Sent: Wednesday, June 28, 2006 10:17 AM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Advanced Unbound Form With Classes andCollectionsP
> art 3
>
> ...I meant as an article on your site or dba's.
>
> William
>
> ----- Original Message ----- 
> From: <DWUTKA at marlow.com>
> To: <accessd at databaseadvisors.com>
> Sent: Wednesday, June 28, 2006 10:35 AM
> Subject: Re: [AccessD] Advanced Unbound Form With Classes andCollectionsP
> art 3
>
>
>> Honestly I'm writing it as I go.  DBA's lists are the only lists I'm
>> really
>> on anymore.  I get on Woody's Lounge once in a blue moon.
>>
>> Drew
>>
>> -----Original Message-----
>> From: William Hindman [mailto:wdhindman at dejpolsystems.com]
>> Sent: Tuesday, June 27, 2006 10:39 PM
>> To: Access Developers discussion and problem solving
>> Subject: Re: [AccessD] Advanced Unbound Form With Classes and
>> CollectionsPart 3
>>
>>
>> Drew
>>
>> ...this is pretty good stuff ...do you intend to post it elsewhere as a
>> single article?
>>
>> William
>>
>> ----- Original Message ----- 
>> From: "JWColby" <jwcolby at colbyconsulting.com>
>> To: "'Access Developers discussion and problem solving'"
>> <accessd at databaseadvisors.com>
>> Sent: Tuesday, June 27, 2006 8:08 PM
>> Subject: Re: [AccessD] Advanced Unbound Form With Classes and
>> CollectionsPart 3
>>
>>
>>> Drew,
>>>
>>>>Public Function NewEnum() As Iunknown
>>>
>>> Is this a dedicated syntax thing or can I do this multiple times for
>>> multiple collections in the same class?
>>>
>>> Public Function NewEnum1() As IUnknown
>>>
>>> Set NewEnum1=PeopleByFirst.[_NewEnum1]
>>>
>>> End Function
>>>
>>> Public Function NewEnum2() As IUnknown
>>>
>>> Set NewEnum2=PeopleByLast.[_NewEnum2]
>>>
>>> End Function
>>>
>>> John W. Colby
>>> Colby Consulting
>>> www.ColbyConsulting.com
>>>
>>> -----Original Message-----
>>> From: accessd-bounces at databaseadvisors.com
>>> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
>>> DWUTKA at marlow.com
>>> Sent: Tuesday, June 27, 2006 2:58 PM
>>> To: accessd at databaseadvisors.com
>>> Subject: [AccessD] Advanced Unbound Form With Classes and Collections
>>> Part
>>
>>> 3
>>>
>>> We have built a 'collection class' in our demo, the People Class.  It is
>>> an
>>> object representing all of the people in our database.  We can retrieve
>>> people from it either with their ID, or by their sort order (first or
>>> last
>>> name sort).
>>>
>>>
>>>
>>> But why can't we do a For Next loop?  I mean, our class represents
>>> multiple
>>> Persons, so it contains all of the Person classes, why are we forced to
>>> use
>>> an index or position to retrieve a person?
>>>
>>>
>>>
>>> Surprise, we're not.  Though to get this capability requires a little
>>> 'outside of the box' work.  Here's what we need to do.  First, we need 
>>> to
>>> add a function to our People class:
>>>
>>>
>>>
>>> Public Function NewEnum() As IUnknown
>>>
>>> Set NewEnum=PeopleByFirst.[_NewEnum]
>>>
>>> End Function
>>>
>>>
>>>
>>> The next portion is a little tricky in Access.  We need to set this
>>> procedure's 'id' to -4.  In Visual Basic 6, you can do this by clicking
>>> Tools>Procedure Attributes, and then clicking the Advanced button.  I
>>> looked, couldn't find this in Access, but all's not lost.  We can still
>>> do
>>> this.  Right click on the People class in our demo project's code 
>>> window.
>>> Select Export File.  Save it somewhere.  Now go and open that saved file
>>> in
>>> Notepad.  You'll see the code of our class with some extra stuff thrown
>>> in.
>>> What we need to do is add a line in our NewEnum function so it looks 
>>> like
>>> this:
>>>
>>>
>>>
>>> Public Function NewEnum() As IUnknown
>>>
>>> Attribute NewEnum.VB_UserMemId = -4
>>>
>>> Set NewEnum=PeopleByFirst.[_NewEnum]
>>>
>>> End Function
>>>
>>>
>>>
>>> Once this is done, let's test it.
>>>
>>>
>>>
>>> Create a form with a button, and put the following code behind it:
>>>
>>>
>>>
>>> Dim ps as Person
>>>
>>> Dim ppl as People
>>>
>>> Set ppl=New People
>>>
>>> For Each ps in ppl
>>>
>>>            Debug.print ps.FullName
>>>
>>> Next
>>>
>>> Set ps=nothing
>>>
>>> Set ppl=nothing
>>>
>>>
>>>
>>> Now press the button and run our test code.  Whalla!  We can now loop
>>> through the Person objects in our People Collection with a For Next 
>>> loop!
>>>
>>>
>>>
>>> So now that we know about collections, and we have created the same
>>> functionality of a collection with our own 'collection class', let's go 
>>> a
>>> step further, and make our Person class 'aware' of it's collection 
>>> class.
>>> We'll do this in the next part.
>>>
>>>
>>>
>>> Drew
>>>
>>> --
>>> AccessD mailing list
>>> AccessD at databaseadvisors.com
>>> http://databaseadvisors.com/mailman/listinfo/accessd
>>> Website: http://www.databaseadvisors.com
>>>
>>> -- 
>>> AccessD mailing list
>>> AccessD at databaseadvisors.com
>>> http://databaseadvisors.com/mailman/listinfo/accessd
>>> Website: http://www.databaseadvisors.com
>>>
>>
>>
>>
>> -- 
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>> -- 
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>>
>
>
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 






More information about the AccessD mailing list