Sub Statement

Sub Statement

In Microsoft Access, a public Sub procedure in a standard module is available to all other procedures in the current database and in referencing Microsoft Access databases. However, it is not available to any other applications.

If you declare a Sub procedure as private in any module, that procedure is available only to other procedures within the same module.

If a Sub procedure is declared as public within a private module, such as a class module, then the procedure is available to all other procedures in that database, but is not available to other Microsoft Access databases.

When you create an event procedure for a form or report, Microsoft Access automatically inserts a code stub for a Sub procedure and precedes it with the Private keyword. For example, create a command button on a new form, set its OnClick property to [Event Procedure], and click the Build button to view the form's module. Microsoft Access inserts the following code for you in the module.

Private Sub Command0_Click

End Sub

You can then enter the code that you want to execute when that button's Click event occurs.