The Linux Page

MS Access classes

As most people know, all of the MS-Office macros are written in Visual Basic.

Visual Basic is for sure a huge whole lot better than the BASIC I had on my Apple //c. For one thing, it does not require line numbers and you can declare functions, procedures, and have local variables (FOR loops that use the variable I do not overwrite the variable I of the FOR loop from the calling function!)

Since MS-Access 2007, we have the possibility to create classes!

Now, there are funny things in MS-Office. Somehow, in MS-Access the constructor in a class is not defined with New(). It is instead Class_Initialize().

Visual Basic has two destructors called Dispose and Finialize. The Dispose is used to free managed resources. The Finalize is used to free the rest. (more or less)

Since you do not need to clear variables since the language does it for you, you most certainly will rarely need a destructor unless your object deals with a database or some other extern resource.

Private m_table_name As String
Public Sub Class_Initialize(table_name)
	m_table_name = table_name
End Sub

Define other functions and procedures as usual, and these become members as you would expect.

This is really good since you can now make all the variables in the class private (you should do so, trust me, I have been programming for a long time!) This means you can modify the variables only from within the class and thus it is much safer.