Online Book Reader

Home Category

Access Cookbook - Ken Getz [167]

By Root 1790 0
and keep all your forms loaded, because they will take up memory.

Like the Form_Open event procedure attached to the switchboard form, the acbOpenForm function passes the string "StayLoaded" to a form via its OpenArgs argument when you pass True as the function's second parameter. Closing the application form is then handled by acbCloseForm, which is called by the Click event of each form's Close button. This function determines whether to close or hide the form by checking its OpenArgs property, which was passed to the form when it was opened:

If InStr(frmToClose.OpenArgs, "StayLoaded") > 0 Then

frmToClose.Visible = False

Else

DoCmd.Close acForm, frmToClose.Name

End If

For forms that you do not wish to preload, don't add them to zstblPreloadForms. For forms that you wish to close normally when the Close button is pressed, open them using the following syntax:

=acbOpenForm("formname", False)

If you have enough memory, you may wish to preload all forms and not close them until the application exits. In some situations, however, you may wish to be more selective. By using the preload technique and the acbOpenForm and acbCloseForm functions throughout your application, you can easily change your mind or customize form preloading and form hiding for different requirements.

We did not remove from each sample form the Close button and control box provided by the system. This means that you can use one of these alternate mechanisms to bypass the application-defined Close button (and the acbCloseForm function) and close the form instead of hiding it. Thus, you may wish to set the CloseButton and ControlBox properties of your forms to No to prevent the use of these mechanisms.

You may wish to make zstblPreloadForms a hidden table. You can adjust the hidden property of an object by selecting View → Properties.

BENCHMARKING 101

Benchmarking different scenarios is a painstaking process. Because Windows includes a hard disk cache and because Access itself caches data, it's difficult to get fair and accurate timings. Because of caching, the order in which you time things does matter. Avoid jumping to conclusions without repeating the readings several times in different orders. Also, there is no reliable programmatic way to measure the time a form takes to load. Although you can set timers at each of the form's events, Access does some things internally after the last loading event has fired. You will find that the only accurate way to test a form's loading time is to manually test and average the form load using a stopwatch.

8.2. Make Slow Forms Run Faster


Problem


You are not happy with the speed at which your forms load and display. How can you change your forms so they will load and display faster?

Solution


Access gives you a lot of flexibility to develop dynamite-looking forms. Unfortunately, Access also makes it easy to create forms that run painfully slowly. The Solution in Recipe 8.1 explained how you can speed up the loading time of all forms by preloading them. This solution discusses how to track down and fix various performance bottlenecks, thus improving form execution performance. We also discuss the use and misuse of graphic elements and combo and list box controls.

You should consider several potential issues when analyzing your forms for performance. We discuss here two common performance bottlenecks: controls involving graphic or memo field data, and combo and list box controls.

Graphic and memo controls


Load the 08-02a.MDB database. Open the frmCategoriesOriginal form (see Figure 8-5). This form, although attractive, loads slowly and has a noticeable delay on slower machines when moving from record to record. Now open frmCategoriesStep3, which is the final version of the form after various optimizations have been applied to it (see Figure 8-6). Its load and execution times should be noticeably faster.

Figure 8-5. The original form, frmCategoriesOriginal, is slow

Figure 8-6. The final form, frmCategoriesStep3, is faster

Follow these steps to improve the performance

Return Main Page Previous Page Next Page

®Online Book Reader