Using Events with the Database Object
The Database object includes support for the following events: DatabaseSaved, DatabaseCreated and DatabaseOpened. Procedures, which respond to these as well as the other available events, are written into the ThisDatabase class module (open the Procedure drop-down list box to view the complete list of events). You can create an event procedure by following these steps:
1.Double click on ThisDatabase in your template project or database project in the "Project Explorer" window. (In the folder view, ThisDatabase can be found in the FlexPro Objects folder.)
2.Select Database from the Object drop-down list box.
3.Select an event from the Procedure drop-down list box.
An empty sub-routine is added to the class module.
4.Add the Visual Basic instructions to be executed when the event occurs.
The following example shows a DatabaseCreated event procedure in a template project, which is executed when a new database is created.
Private Sub Database_DatabaseCreated(ByVal Database As Object)
MsgBox "New database created"
End Sub
The following example shows a DatabaseModified event procedure in a database project that runs only after the database has been changed.
Private Sub Database_DatabaseModified(ByVal Database As Object)
MsgBox "Database modified"
End Sub
If an auto-macro exists in a database and template database, only that automatic macro, which is stored in the database, is executed. If an event procedure for a Database event exists in a database and template database, both event procedures are executed.
Note: For information on the creation of event procedures for the Application or Databases object, go to Using Events with the Application or Databases Object.