Article ID: 324589 - Last Review: August 2, 2004 - Revision: 4.0 How to use lightweight objects in Access 2002This article was previously published under Q324589 On This PageSUMMARY This article first describes lightweight objects and shows
you how to make an object lightweight. It then shows you how to create a
lightweight switchboard form that uses the Hyperlink properties of form controls to open other objects in a database.
Lightweight objects first appeared in Microsoft Access 97. Lightweight forms and reports are objects that do not contain a class module. This makes lightweight objects smaller. Lightweight objects typically load and are displayed faster. They also make your database smaller. A disadvantage may be that a lightweight object does not appear in the Object Browser. Also, you cannot use the New keyword to create a new instance of a lightweight object. By default, all new forms and reports are lightweight. Access creates a class module for the object only if you do one of the following:
Making an Object LightweightYou can convert an existing object that has a class module to a lightweight object by setting its HasModule property to No, and then saving the object.WARNING: If an object has a class module, and you save the object with a HasModule property set to No, its class module and any code it contains are deleted. If an object must perform certain actions that are assigned to events, you do not necessarily have to add modules to the object. Instead, you can use a macro or a public function. Method 1: MacroIf the code to perform certain actions is not complex, you can rewrite the code as a macro. Then, you can have the event call the macro instead of the code. This keeps the object lightweight.For example, if a form has a Click event for a command button that previews a report that is named Sales by Category, you can create the following RunReport macro: RunReport Action Arguments ------------------------------- OpenReport Report Name: Sales by Category View: Print Preview RunReport NOTE: If you want your macro to perform some actions and then to run
Visual Basic for Applications code to do the rest, you can have the macro call
a Visual Basic for Applications function with the command RunCode, as follows: RunReport Action Arguments ------------------------------- OpenReport Report Name: Sales by Category View: Print Preview RunCode Function Name: MyFunction() Method 2: Public FunctionYou can also have the event in the object call a public function. If an object has an event that calls a public function, the object is still lightweight. By using the example in Method one, you can write a generic function that runs reports. You can then put that generic function in a public module. You can then call that function from the Click event. To see how this works, follow these steps:CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
This method does not add a module to the form. Therefore, the form is still a lightweight form. Method 3: HyperlinkBy using the Hyperlink property of command button controls, label controls, and image controls, you can create a lightweight switchboard form in your database that does not use any Visual Basic code or macros.The following example shows you how to create a switchboard form that uses hyperlinks to open database objects:
REFERENCESFor
more information about the HasModule property, click Microsoft Access Help on the Help menu, type HasModule property in the
Office Assistant or the Answer Wizard, and then click Search to view the topics returned. For more information about class modules, click Microsoft Access Help on the Help menu, type class modules in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned. For more information about the HyperlinkSubAddress property, click Microsoft Access Help on the Help menu, type HyperlinkSubAddress property in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.
| Article Translations
|
Back to the top
