ACC97: Using Lightweight Objects in Microsoft Access 97

ID: Q159827


The information in this article applies to:


SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article describes the concept of lightweight objects and provides a technique to create a lightweight switchboard form in Microsoft Access 97 that uses the Hyperlink properties of form controls to open other objects in the database.

NOTE: A demonstration of the technique used in this article can be seen in the sample file, FrmSmp97.exe. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:

Q175066 ACC97: Microsoft Access 97 Sample Forms Available on MSL


MORE INFORMATION

Microsoft Access 97 introduces the concept of lightweight forms and reports, which are objects that do not contain a class module. One advantage of lightweight objects is that they are smaller and typically load and are displayed faster than objects with class modules. Another advantage is that they help decrease the size of your database because they do not require storage space for a class module. 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.

When you create a new form or report, it is a lightweight object by default. Microsoft Access 97 only creates a class module for the object if you do any of the following:

Note that you can still use macros in lightweight objects, as well as public procedures that exist in standard modules.

You can convert an object with a class module into a lightweight object by setting its HasModule property to No, and then saving the object. Do so with caution, however, because once you save the object, its class module and any code it contains are deleted.

By 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:
  1. Open the sample database Northwind.mdb.


  2. Create the following new form not based on any table or query in Design view:
    
          Form: MySwitchboard
          --------------------------------------
          Caption: Main Menu
    
          Command button:
             Name: OpenEmp
             Caption: Employees Form
             HyperlinkSubAddress: Form Employees
          Label:
             Name: OpenCat
             Caption: Catalog Report
             HyperlinkSubAddress: Report Catalog
          Image:
             Name: OpenSales
             Picture: C:\Windows\Circles.bmp
             PictureType: Embedded
             SizeMode: Clip
             PictureAlignment: Center
             PictureTiling: No
             HyperlinkSubAddress: Query Category Sales for 1995 

    NOTE: If you do not have the file C:\Windows\Circles.bmp, you can substitute another bitmap or graphic file on your computer in the Picture property above.

    Note that the HasModule property of the form is set to No. That is how you can tell this is a lightweight form.


  3. Save the MySwitchboard form, and then open it in Form view.


  4. Click the Employees Form button, the Catalog Report label, and the image control and note that each one opens the object specified in its HyperlinkSubAddress property.



REFERENCES

For more information about lightweight objects, search the Help Index for "lightweight objects."

For more information about class modules, search the Help Index for "class modules," or ask the Microsoft Access 97 Office Assistant.

For more information about the HyperlinkSubAddress property, search the Help Index for "HyperlinkSubAddress property," or ask the Microsoft Access 97 Office Assistant.

Additional query words: class lightweight bloat menu switchboard


Keywords          : FmsProp FmsHowto 
Version           : 97
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 20, 1999