Option Private Statement
Description
When used in host applications that allow references across multiple projects, Option Private Module prevents a module's contents from being referenced outside its project. In host applications that don't permit such references, for example, standalone versions of Visual Basic, Option Private has no effect.
Syntax
Option Private Module
Remarks
If used, the Option Private statement must appear at module level, before any procedures.
When a module contains Option Private Module, the public parts, for example, variables, objects, and user-defined types declared at module level, are still available within the project containing the module, but they are not available to other applications or projects.
Note Option Private is only useful for host applications that support simultaneous loading of multiple projects and permit references between the loaded projects. For example, Microsoft Excel permits loading of multiple projects and Option Private Module can be used to restrict cross-project visibility. Although Visual Basic permits loading of multiple projects, references between projects are never permitted in Visual Basic.
See Also
Option Base statement, Option Compare statement, Option Explicit statement, Private statement, Public statement.
Specifics (Microsoft Access)
When you include the Option Private statement in a standard module in Microsoft Access, any public variables or procedures in the module are still available to all other procedures in the current database. However, they are not available to procedures in other databases.
Since class modules are private by default, including the Option Private statement in a class module generates an error.
Example
This example demonstrates the Option Private statement, which is used at the module level to indicate that the entire module is private. With Option Private Module, module-level symbols not declared Private are still available to other modules in the project, but not to other projects or applications.
Option private Module ' Indicate that module is private.