Messed up with Class Modules

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm praying for an Angel to bless me with a sample db engineered to the max
with Class Modules so that I can play around, just like what I did with
Northwind.mdb when I started out with VBA.

Thank You.
 
Hi Sreedhar,

send me an email and I will send you some db's to learn from

be sure to include something to that effect in the subject line

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
This is a good opportunity - given that there are two MVPs contributing to
the thread - of discussing the relevance of class modules to Access. In my
opinion Access' strengths lie in the provision of a very good relational
database management system plus excellent GUI and report design tools. (Let
me also applaud the query design grid.) However I contend that there is a
basic incompatibility between a conventional relational database and class
modules.

Don't get me wrong; I do use class modules quite a lot and as Alex has
pointed out all forms are already class modules, so we all (unwittingly) use
class modules. Where I experience the incompatibility is in saving object
data into tables. As I understand it (I never use it) the only way to save
object data is as a text string via the scripting runtime library. I have
tried building 'wrapper' classes to retrieve and store table data but these
inevitably end up being complex and cumbersome, I just seem to be adding
another unnecessary layer between my code and the data.

A disappointment is that Access does not provide implementation inheritance,
so even if I design a class/subclass structure I still have to code each and
every property and method in each and every subclass. Will this be corrected
in 2007?

Oh there's also a glitch that I notice when opening forms as class modules.
Open a modal form using OpenForm and the remainder of the code below that
statement does not execute until the form is closed - kind of what I would
expect. However instantiate a new modal form and code execution continues
until end of procedure. If possible I would like code execution to stop when
the form is made visible. (2007?)

There are some situations where class modules are a must: support for
Treeview and other OCXs (as Alex implies); other MS Office applications and
objects within those applications; user-defined events.

I find that my Access applications are never completely procedural or OOP
but a hybrid. I make this post to invite others to comment on when, how and
why they use class modules.

Regards,

Rod
 
Where I experience the incompatibility is in saving object
data into tables. As I understand it (I never use it) the only way to
save
object data is as a text string via the scripting runtime library.

We don't have any built in serialization of objects in ms-access, and that
double applies to class objects that you create. On the other hand, really
storing the state, or values of a object you crate is VERY much different
then simply storing customer data in a table. You can't really store that
customer information in anything but a standard relational data table.
Often we see a person go hog wild on OO, and start storing data
of a customer in this fashion...the end result is useless, since you
can't use standard reporting tools, or even sql quires on this type
of serialized data.

So, sure...I wish we had some type of serialization to store the all of
the data for a class object we create. This would be great for
saving the state of a object, or even loading/saving them.
So, this is good as long as we throw cold water on this idea
that this class object data should some how store our
customer data in a serialized format that is of NO USE
for reports, or sql quires. Doing this ties the data
to code.
A disappointment is that Access does not provide implementation
inheritance,
so even if I design a class/subclass structure I still have to code each
and
every property and method in each and every subclass. Will this be
corrected
in 2007?

ms-access shares the same code syntax (and in fact the same compiler) as
vb6.
It is not likely that the vba will be modified in this way. What likely will
happen
is that events will be able to be sub-classed out your .net environment in
the future, and thus would then use .net..and not vba. This was done
in office 2003 for word and Excel. However, the ability to use .net code
for ms-access was not changed, and nor is it for access 2007. I
am speculating here..but, since you can now replace your vba code
in word, or excel with .net code, I would expect the same idea in
ms-access. This would thus allow you to keep existing applications
(there is several 100's million copies of ms-access out there...and
we can't break all of that!!!).

Oh there's also a glitch that I notice when opening forms as class
modules.
Open a modal form using OpenForm and the remainder of the code below that
statement does not execute until the form is closed - kind of what I would
expect

the above is incorrect. You are thinking of a dialog form...not a model
form.
Model forms never halted the calling code (or, in your case, when you
instance a form/class object).

I explain the difference here:
http://www.members.shaw.ca/AlbertKallal/Dialog/Index.html
However instantiate a new modal form and code execution continues
until end of procedure. If possible I would like code execution to stop
when
the form is made visible. (2007?)

I don't want to split hairs on semantics. It is clear that you did mean
dialog
forms here!!! And, what you say above is correct.

The general approach/workaround I use is have the new form instance
create a reference to the form that created the new form instance, and
choose a common event name for the new form to execute when it
closes. So the instance of the form will execute code from the calling
form when "ok" is hit, or the form is closed.
This means your calling code will not wait, but you
just transfer control to a whole new routine after the form is done.
This is certainly not very clean..but, it does work, and is what I do now.
I find that my Access applications are never completely procedural or OOP
but a hybrid.

Yes, I agree!...You above analyses is spot on. we do have class objects, but
one does
not have the traditional full OO features that one would expect. Further,
we are not
procedure due to the event driven nature of ms-access.
I make this post to invite others to comment on when, how and
why they use class modules.

For all the readers here is my comments on using objects in ms-access....

http://www.members.shaw.ca/AlbertKallal/Articles/WhyClass.html
 
Hi Rod,
yes, access is not 100% OOP. but, IMHO, this is not a problem. I have built
some applications using OOP (well, also not 100% OOP) on VB6, but this was
never required in Access. I think this is because of whole idea of Access -
when you build something on Access - you using other concepts.
Actually one my colleague once made an access application with objects and
all this staff, but this was some import-export processor, and did not use
native Access features.

--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
Hi Albert,

Yes of course I meant 'dialog' it's just that my spelling is atrocious :-)
Seriously thanks for picking up that clanger.

Regards,

Rod
 
Hi again, Albert.

I've just had an opportunity to read through the article referenced by your
second URL. I think it's a good example of when class modules are useful:
you are dealing simultaneously with more than one 'set' of data and each of
your instatiated objects will contain and manage its own unique 'set' of
data; the complexity is 'banished' to the class properties and methods
thereby making your main procedural code more concise, cleaner and
self-documenting (given meaningful property and method naming).

However I have a couple of questions/comments.

The example form you display shows two tours, one on the left and one on the
right. Is this implemented by having two subforms bound to your Access
tables or are you managing it by poking object data into unbound controls? I
ask because wouldn't it be nice to be able to bind a form to an object? I
have visions of being able to define a recordset property from within a class
module - somewhat akin to defining a user data type - and then having Access
populate all the bound controls on the form automatically. At present
binding a form to the underlying tables while simultaneously using objects
based on those same tables can lead to sychronization problems: there is no
guarantee without explicitly programming it that the table data and the
object data are identical.

I assume that in your example the tour object is populated at the time of
class_initialize (or soon after- perhaps when you provide the Id property).
Do you notice any performance hit? Probably not since the application has to
do the same work whether its performed in the main procedure or in the class
module. This leads me onto another of the items on my wish list. Wouldn't
it be nice to be able to supply arguments to the class_initialise method? So
instead of coding Set objTour = New clsTour we instead code Set objTour = New
clsTour(TourId). All the object population can now be performed inside the
class_initialize since we know the identity of the tour at this time. One of
the subsidiary reasons I stopped trying to use 'wrapper' object for database
access was that I had to include a separate populate method to load specific
data into a class module instance.

Just a final observation: I have recently disciplined myself to use ADODB
Command objects wherever possible and find the command with parameters most
useful. In fact in your example they would be most appropriate for
retrieving the tour data. Why use commands rather than other constructs?
Well, they reduce the number of Queries and/or remove the SQL complexity for
the main procedural code. In fact I have gone as far as completely
encapsulating the command in a separate module or class module, each method
or procedure returns an ADODB.Recordset. The simplicity of the resulting
main procedural code is astounding, for example:

Dim rstTour as ADODB.Recordset
Set rstTour = cmdGetTour(TourId)

Regards,

Rod
 
Sreedhar,

Many apologies for 'hijacking' your thread but when you've finished reverse
engineering any class module mdb you receive come back here as there are good
thoughts and useful links.

Regards,

Rod
 
Hi everybody,

I was out-of-station for the last three days and couldn't follow this
thread. But, I'm happy to see the reflections of all those who participated
in this thread.

Currently, I'm playing around with class modules from purely an academic
point of view, and hence the thoughts and reflections that this thread
gathered are invaluable to me.

I must say thanks to you, Rod !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top