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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

standalone classes for multiple access DB's to share common code 3

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I have a few MS applications for different departments, each has identical code for certain features.

Each time a change is made in one I have to make the same change in all the others.

How do i take the VBA code out of MS access so it is a stand alone class that all the DB's use so I then only ever need to make changes in one place and all the applications use the class in a proper OO manner.

Would I create a separate MS DB which the others link to? or import from?

Do i turn the class module into a DLL or a .vb file?

all advice appreciated


Thanks,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
OK, I am giving you a star because I am learning more from this post than you.

Kaplan and Kreft, who wrote the "VBA developers Handbook" got it completely wrong as you pointed out. I unfortunately bought into this without testing it, and ended up confusing both of us. Sorry for that. So much for the "experts"
In order to create an instance of a Class residing in an MDA, you have to follow one of these two ways .
The easiest way is to write a function in your Library db which returns an instance of your class.
The second one is a bit more involved....

It should read "both of these ways" not "one of these two ways". The "method 2" is exactly the same as setting the instancing to "public not createable". (The reason they did this with the text editor is that this was in some older version of vba. As you pointed out this is now an option in the IDE. This only exposes the methods and properties and allows intellisense.) In order to create the instance you still have to provide a function in your library, because you cannot create a "New" instance of the class in your calling db. I cannot find any explanation for this except as the KB pointed out "it is just the way it is."

Second, I learned that a reference to a library does more than just allow you access to the code "without opening the library." In fact, and of course, it does open the library. That is why you see the project in the IDE and you will also see a lock file on the library. So as you pointed out there is no need to create an new instance, because it is already open.

Once we are done this probably worth a developing a FAQ.
 
I await my star, I certainly feel like i've earned it.

Why didn't you say to start with it was the blind leading the blind, there was me thinking you knew what you were doing and had done this before :p

As I originally said it seemed bizarre and goes against OOP when you can declare an object of a class type but then cant instantiate the damn thing nor is therre a constructor to speak of!

Ever opened a can to find nothing but worms, but once the cat is out the bag, you're left with an elephant in the room!


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Another very annoying thing, is allthough the public library functions that are coded in standard module are visible, the publicly declared variables aren't!

So my main DB now has an oUser object from the library class, great!

I then use the method I described to open the login form in the library DB, but then when I try to reference the public oUser object from the form I get an object required error.

So the public global var in the main DB oUser is not visible from the library DB!

Interestingly , when I wrote the code on the form, the case shifted so it could see (for intelisense purposes) the object existed, but you can't actually access it?

OOP with MS Access is very tricky indeed!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
ok, i'm forgetting data hiding and encapsulation principles!

If i'm going to expose any of the standard module code global vars, I need getter/setter accessor methods....

That's it for me till next week, I booked a long weekend with the wife , so not back in till tuesday, looks like I could do with the break anyhow!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
You should not have any globals in the library database for classes. That is just violating all principles of OOP. However keep in mind a form's module is a class module. so if on my form.

Private mSomeProperty As Object

Public Property Get SomeProperty() As Object
Set SomeProperty = mSomeProperty
End Property
 
hmm, I haven't had a chance to work on this , just back from a long weekend, so lots of stuff to catch up on...

However, a global variable or method should be possible, in fact my course has just covered this, they call them 'shared fields' or 'shared methods', Also my Java course showed you can have Class variables.

These are what i am trying to create but don't seem to be able to work it out in MS Access

The oUser object needs to be referenced by an application wide variable.

Where would I declare and initialise this to make it application wide so both the main DB and the library DB can get access to it?

I thought perhaps using the module name as the prefix of the dot notation would work , as you do with classes ie. ClassName.VariableName or ClassName.Method , but that doesn't seem to work.

any ideas?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
If you want to make oUser public, it goes in a standard module in the library.

public oUser as new clsUser

the calling database can reference this variable as
yourLibraryName.oUser

The new will instantiate the variable when the library loads as a clsUser object.

 
cool, I'll try it out when I get a chance. MD got me doing the company chrimbo card now!

Why because you do IT they think your a whizz at aything on a computer I don't know, graphics is my weakest link!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top