Accessing Module method in a Class Module

access83

Registered User.
Local time
Today, 16:45
Joined
Apr 25, 2012
Messages
22
Hi All,

I'm creating my own Class in vba for the first time and I was wondering if I can access a method (sub) I've created in a Module from within a class. My idea is to have an Employee class and one of the methods I would like to have for this class is AddNewEmployee. This method will add the new employees details to a table on SQL Server. To do this I need to connect to the server so I have my connection method within a Module. I don't want this in the Employee class as I want to create other classes which will have methods that need to connect to SQL Server. Does anyone know if I can do this?

Thanks in advance :)
 
You can access any functions, subs or variables from a module (or anywhere in your project) as long as they are declared as Public.
 
Great..Thanks :)
 
I use a mix of both Classes and Modules. Since I saw SQL Server mentioned... for ADO Objects I create one ADO.Connection object at application startup, place it in a global object, and fetch it from that object each time an ADO.Command / ADO.Recordset needs the Connection object.

For common code used across all DB classes which wrap a particular type of logical record (Project / Product / Part / PO / etc...) I make calls form the DB class code to Global code in Modules. For example, I have shared code to download records from SQL Server into an Access FE temp table.

Example of DAO.QueryDef objects downloading records from a SQL BE DB via Pass-Through query and populating a FE temp table with them
http://www.access-programmers.co.uk/forums/showthread.php?p=1119605&posted=1#post1119605

I also have shared code to empty the FE temp table. Each DB class has an EmptyLocalTmpTbl() func, which make a call to the shared dbutils_EmptyLocalTmpTbl() passing in the name of the FE temp table as defined in the DB class.

Classes are good to be able to reuse code, however there are still valid reasons to use non-OO Procedures in the OO Class world.
 

Users who are viewing this thread

Back
Top Bottom