Repetitive coding in class modules

G

Guest

I'm trying to use class modules and find myself using the same code
repetitively for property get and let statements, retrieving rows, and saving
data in unbound forms. The only real difference is the table or query I'm
working with. Is there a way to programatically create code with fields
inserted and write it to a class module or a form's class module?
 
A

Albert D.Kallal

Well, if that data is going to come form a table, then why not add a
reocrdset to the class module..and expose it?


public rstData as recordset


Now, you can go:


msgbox "the company names is = " & myclassOjbect.rstData!CompanyName

However, it sounds to me that you likely don't need a class object (module)
here.

Further, you do realize that any form in ms-access is a class object, and
you can have multiple instances of that form....

So, this begs the question...why not just put your code in the form? Any
public function declared in a forms code module becomes a method of that
form.

public Function DoSomeStuff


You can then go with the forms object


MyForm.DoSomeStuff


In fact, if you declare the forms object as

dim MyForm as new forms_NameOfYourForm

Then even inti-sense will work when you go

MyForm.DoSomeStuff

Anyway, at the end of the day, it makes no sense at all to build a zillion
get/let statements to retrieve data that can be grabbed from a recordset.
Further, you don't have any serialization ability built into the class
objects, and thus I don't see why data in a table is trying to extracted via
a let/get pair...this is not going to yield any improvement in your
code...nor save anytime either..
 
G

Guest

The book I was reading recommended class modules, but, like you said, I was
writing "a zillion get/let statements." Your comments make sense, but when do
you use class modules?
 

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

Top