Using Events with the Application or Databases Object
To create an event routine for an event affecting the Application or Databases object, carry out the following three steps:
1.Declare an object variable in a class module so that the events will be answered.
2.Write the specific event procedures.
3.Initialize the declared object from another module..
Declaring the Object Variable
Before you can write procedures for the Application or Databases object events, you have to create a new class module and declare an object of the Application or Databases type with events. Let us assume that a new class module called "EventClassModule" is created. The new class module contains the following code:
Public WithEvents App As FlexPro.Application
or
Public WithEvents Databases As FlexPro.Databases
Writing Event Procedures
After the new object with events has been declared, it appears in the Object drop-down list box in the class module, and you can write event procedures for the new object. (If you select the new object in the "Object" list, the valid events for the object are listed in the Procedure drop-down list box.) Select an event from this list. An empty procedure is added to the class module.
Private Sub App_DatabaseModified(ByVal Database As Object)
End Sub
or
Private Sub Databases_BeforeDatabaseClose(ByVal Database As Object)
End Sub
Initializing the Declared Object
Before the procedure can run, a connection has to be established between the declared object in the class module ("App" or "Databases" in this example) and the Application or Databases object. This connection can be set up using the following code from any module:
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.App = FlexPro.Application
Set X.Databases = FlexPro.Databases
End Sub
Start the "Register_Event_Handler" procedure. Once the procedure has been executed, the App object in the class module references the FlexPro Application object and the database object with regard to the Databases object. The event procedures in the class module are then called as soon as the events occur.