[AccessD] Advanced Unbound Form With Classes andCollectionsPart 3

Jim Lawrence accessd at shaw.ca
Wed Jun 28 14:28:27 CDT 2006


Hi John:

I have already spoken to Drew and he is fine as far as I know.... Correct Drew? I will not be back until after July the 9th and was then hoping to assemble an article on Drew´s simple ADO classes on the DBA web site. If you wish to assist, or anyone else for that matter please feel free (Susan comes to mind) and we can proceed without much delay.

Jim  

----- Original Message -----
From: JWColby <jwcolby at colbyconsulting.com>
Date: Wednesday, June 28, 2006 4:00 am
Subject: Re: [AccessD] Advanced Unbound Form With Classes andCollectionsPart	3

> Like on DatabaseAdvisor's web site?
> 
> ;-)
> 
> John W. Colby
> Colby Consulting
> www.ColbyConsulting.com
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [accessd-bounces at databaseadvisors.com] On Behalf Of William Hindman
> Sent: Tuesday, June 27, 2006 11:39 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Advanced Unbound Form With Classes 
> andCollectionsPart3
> 
> 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
> > [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 
> collectionclass.
> > 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
> 




More information about the AccessD mailing list