The information in this article applies to:
This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp). Moderate: Requires basic macro, coding, and interoperability skills. SUMMARYThis article describes the concept of lightweight objects and provides a technique to create a lightweight switchboard form that uses the Hyperlink properties of form controls to open other objects in the database. MORE INFORMATION
Lightweight forms and reports, which are objects that do not contain a class module, were first introduced in Microsoft Access 97. One advantage of lightweight objects is that they are smaller and typically load and are displayed faster than objects with class modules. Also, because they require no storage space for a class module, they can decrease the size of your database. Possible disadvantages of using lightweight objects is that they do not appear in the Object Browser, and you cannot use the New keyword to create a new instance of 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. Making an object LightweightIf you need an object to perform certain actions assigned to events, there are techniques to doing this without adding any modules to the form.Method 1If the code is not very complex, you can re-write it as a macro and have the event call the macro instead of the code. If you call a macro, the form remains lightweight.For example, if on a form you have a Click event for a command button that previews a report called Sales by Category, you could create the following macro called RunReport
and then set the OnClick property of the command button to the following:RunReportNOTE: 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 in the following example:
Method 2You can also have the event assigned to the object call a public function. An object is still lightweight if it has an event that calls a public function. Using the example in Method one, you could write a generic function that runs reports and place that in a public module. You can then call that function from the Click event. To see how this works, follow these steps: CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.
By using this method, the form has no module behind it, and therefore it is a lightweight form. Yet, you have the ability to call Visual Basic for Applications code. And you can still specify which report you want to preview in the Click event. Method 3By 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 creates a switchboard form that demonstrates the use of 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. Additional query words: class lightweight bloat menu switchboard URL URLs
Keywords : kbdta FmsProp FmsHowto |
Last Reviewed: December 2, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |