Online Book Reader

Home Category

Access Cookbook - Ken Getz [166]

By Root 1803 0
in the event property for the button's Click event:

=acbCloseForm(Form)

Don't place any quotes around the Form argument.

Make a copy of the form created in Step 2 and name it frmSplash. This is what's known as a "splash form." Open frmSplash in design view and remove all the command button controls. Also remove all the code behind the form for this copy. In the area where the command buttons used to be, add a label control that contains an initialization message. For example, the label on frmSplash has the attributes shown in Table 8-1. frmSplash is shown in form view in Figure 8-3.

Table 8-1. Properties of frmSplash's lblMessage control

Property

Value

Name

lblMessage

Caption

Initializing...

BackStyle

Transparent

BorderStyle

Transparent

FontName

Arial

FontSize

14

TextAlign

Center

Figure 8-3. The splash form, frmSplash

Open the switchboard form created in Step 2. Open the form's module and add the following constants to the declarations section of the module:

Const acbcPreloadTable = "zstblPreloadForms"

Const acbcSplashForm = "frmSplash"

Change "zstblPreloadForms" to the name of your table from Step 1. Change "frmSplash" to the name of your form from Step 11.

Select Tools → Startup to open the database Startup dialog (see Figure 8-4). Select the switchboard form from Step 2 in the Display Form/Page field.

Figure 8-4. The database Startup dialog

Close the database and reload it to test your startup procedure and switchboard form.

Discussion


Access forms are stored as binary data in hidden system tables in your database. When you load a form, Access reads data from the system tables to recreate and display that form. This takes time. The solution described here improves the application load time of forms by preloading them when the database is first loaded. This means that the initial application load time will be slower, but users are more tolerant of a long application load time because it is a one-time commitment. As with most performance optimizations, the benefits of this technique are especially noticeable on slow machines.

Prior to Access 95, you had to use an AutoExec macro to initiate some action upon database startup; in recent versionsyou can use the Startup dialog to specify a form to be opened when the database is loaded. This solution takes advantage of the Startup properties, but you also could have used an AutoExec macro.

When the switchboard form opens, the form's Open event is triggered and the code attached to the Open event is executed. Unfortunately, when the Open event procedure is called, the form has not had time to paint itself, so users normally see nothing during the Open event procedure. To remedy this, we created a "splash" form to display during the potentially lengthy process. You don't have to make the splash form the same size as the switchboard form, but in this case, we made the two forms very similar in appearance.

The code to preload the forms is shown here:

Set rst = db.OpenRecordset(acbcPreloadTable)

Do While Not rst.EOF

varFormName = rst("FormName")

If Not IsNull(varFormName) Then

DoCmd.OpenForm FormName:=varFormName, _

WindowMode:=acHidden, OpenArgs:="StayLoaded"

End If

rst.MoveNext

Loop

Each record from the zstblPreloadForms table is read and the named form is loaded in hidden mode. In addition, the form's OpenArgs parameter is passed the string "StayLoaded". You can use the OpenArgs parameter of OpenForm to pass a custom string to a form, much as you pass parameters to a function. This OpenArgs parameter will be used later to decide what to do when the preloaded form is closed.

Once the forms have been loaded in a hidden state, you don't need to do anything special to make them appear. Access is smart enough to make a hidden form visible when you attempt to load it, which makes working with invisible forms easy. However, we include wrapper functions for opening and closing your application's forms in case you want some forms to be treated differently. For example, you may not wish to preload

Return Main Page Previous Page Next Page

®Online Book Reader